File size: 6,314 Bytes
c3409a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
 "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": [
       "<div><iframe src=\"https://7a723fc085cc9ad458.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "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": [
       "<div><iframe src=\"http://127.0.0.1:7862/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "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
}