{ "cells": [ { "cell_type": "code", "execution_count": 8, "id": "01032c82-239c-48bf-82dc-cf91a2dd4698", "metadata": {}, "outputs": [], "source": [ "import ollama\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 9, "id": "d17e8da0-72e6-4d11-9f99-64d83d6bb77b", "metadata": {}, "outputs": [], "source": [ "system_prompt_llama = \"You are an assistant that solves a quadratic equation provided. Just write the steps and the final answer and nothing else\"\n", "user_prompt_llama = \"This is the quadratic equation you have to solve: \"\n", "user_prompt_deepseek = \"This is the quadratic equation you have to solve: \"\n", "system_prompt_deepseek = \"You are an assistant that solves a quadratic equation provided. Just write the steps and the final answer and nothing else\"" ] }, { "cell_type": "code", "execution_count": 10, "id": "e5ed88b2-090f-4364-b334-c6ff66676d82", "metadata": {}, "outputs": [], "source": [ "default_equation = \"x² - 5x + 6\"" ] }, { "cell_type": "code", "execution_count": 11, "id": "3aa1ed93-15ea-4d97-a00d-dbda21450ad7", "metadata": {}, "outputs": [], "source": [ "people_dict = {}" ] }, { "cell_type": "code", "execution_count": 12, "id": "9361e9e6-99eb-45b0-ba31-3cf1b0865936", "metadata": {}, "outputs": [], "source": [ "def llama(equation):\n", " message_ = [{'role':'system', 'content':system_prompt_llama}, {'role':'user', 'content':user_prompt_llama+equation}]\n", " res = ollama.chat(model=\"llama3.2\", messages=message_)\n", " return res['message']['content']\n", " \n", "def deepseek(equation):\n", " message_ = [{'role':'system', 'content':system_prompt_deepseek}, {'role':'user', 'content':user_prompt_deepseek+equation}]\n", " res = ollama.chat(model=\"deepseek-r1:1.5b\", messages=message_)\n", " return res['message']['content']\n", " " ] }, { "cell_type": "code", "execution_count": 13, "id": "e6ddaf09-996f-4cfa-af98-49bf1d7d5ab3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7872\n", "* Running on public URL: https://7a723fc085cc9ad458.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with gr.Blocks() as ui:\n", " gr.Markdown(\"## This is a quadratic equation solver\")\n", " with gr.Row():\n", " llama_question = gr.Textbox(label=\"Llama's Question\",value=default_equation,lines=2)\n", " deepseek_question = gr.Textbox(label=\"Deepseek's Question\",value=default_equation,lines=2)\n", " with gr.Row():\n", " llama_answer = gr.TextArea(label=\"Llama's Answer\",lines=10)\n", " deepseek_answer = gr.TextArea(label=\"Deepseek's Answer\",lines=10)\n", " with gr.Row():\n", " llama_solver = gr.Button(\"Solve Llama\")\n", " deepseek_solver = gr.Button(\"Solve Deepseek\")\n", " llama_solver.click(llama, inputs=[llama_question], outputs=[llama_answer]) \n", " deepseek_solver.click(deepseek, inputs=[deepseek_question], outputs=[deepseek_answer]) \n", "\n", "ui.launch(share=True)" ] }, { "cell_type": "code", "execution_count": 7, "id": "0b9ea66f-a97f-4de2-bc60-fd7abbb4cc25", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7862\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gradio as gr\n", "\n", "# A simple function that reacts to a selected mood\n", "def respond_to_mood(mood):\n", " return f\"You selected '{mood}'. I hope your day goes well!\"\n", "\n", "\n", "# Gradio Interface\n", "with gr.Blocks() as ui:\n", " with gr.Row():\n", " area = gr.Textbox(label=\"Answer here\")\n", " inputs=gr.Radio([\"Happy\", \"Sad\", \"Excited\", \"Angry\"], label=\"How are you feeling today?\")\n", " inputs.change(respond_to_mood, inputs=[inputs], outputs=[area])\n", "ui.launch()\n", " \n", " \n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d5b05061-61da-4d2a-8d30-8cff97b7db35", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.11" } }, "nbformat": 4, "nbformat_minor": 5 }