gradio blocks
Browse files- app.py +24 -13
- demo-tools-1.ipynb +164 -31
app.py
CHANGED
@@ -235,16 +235,7 @@ def ask_query(query):
|
|
235 |
# LLM
|
236 |
llm = ChatOpenAI(temperature=0, model_name='gpt-4') # 'gpt-3.5-turbo'
|
237 |
agent = initialize_agent(agent="zero-shot-react-description", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)
|
238 |
-
system = "If the answer is not in the tools or context passed to you then don't answer. \nIf you don't know the answer then say so."
|
239 |
-
# #query = "Can you show tell me what ingredients I need for the first baked chicken recipe?"
|
240 |
-
# #query = "Can you show tell me what ingredients I need for the last baked chicken recipe? "
|
241 |
-
# #query = "What is the best baked chicken recipe? Please look across all recipes with the word 'baked' in the title" # There are 3 baked chicken recipes
|
242 |
-
# #query = "Is there a Chicken recipe that's prepared with an alchohol? And if so how long does it take in total from start time to finish?"
|
243 |
-
# #query = "Which is healthier the Caramel Apple Pie Cookies or the beer chicken? Please explain how you got to your answer."
|
244 |
-
# #query = "Is the moon closer to earth or the sun?"
|
245 |
-
# #query = "How good are the apple pie cookies?"
|
246 |
-
#query = "What tools do I need for the Nutella Ice Cream?"
|
247 |
-
# #query = "My bowl is broken, can I still make Nutella Ice Cream? Answer as a yes/no."
|
248 |
response = agent({"input": f"{system} {query}"})
|
249 |
|
250 |
# Show response
|
@@ -264,9 +255,29 @@ def ask_query(query):
|
|
264 |
resp += response['output']
|
265 |
return resp
|
266 |
|
267 |
-
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
demo.launch(show_error=True)
|
271 |
|
272 |
|
|
|
235 |
# LLM
|
236 |
llm = ChatOpenAI(temperature=0, model_name='gpt-4') # 'gpt-3.5-turbo'
|
237 |
agent = initialize_agent(agent="zero-shot-react-description", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)
|
238 |
+
system = "If the answer is not in the tools or context passed to you then don't answer. \nIf you don't know the answer then say so."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
response = agent({"input": f"{system} {query}"})
|
240 |
|
241 |
# Show response
|
|
|
255 |
resp += response['output']
|
256 |
return resp
|
257 |
|
258 |
+
|
259 |
+
with gr.Blocks() as demo:
|
260 |
+
gr.Markdown("Start typing below and then click **Run** to see the output.")
|
261 |
+
with gr.Row():
|
262 |
+
with gr.Column():
|
263 |
+
inp = gr.Textbox(placeholder="Type your question here?", label="Question")
|
264 |
+
btn = gr.Button("Run")
|
265 |
+
examples = ["Can you show tell me what ingredients I need for the first baked chicken recipe?",
|
266 |
+
"Can you show tell me what ingredients I need for the last baked chicken recipe? ",
|
267 |
+
"What is the best baked chicken recipe? Please look across all recipes with the word 'baked' in the title", # There are 3 baked chicken recipes
|
268 |
+
"Is there a Chicken recipe that's prepared with an alchohol? And if so how long does it take in total from start time to finish?",
|
269 |
+
"Which is healthier the Caramel Apple Pie Cookies or the beer chicken? Please explain how you got to your answer.",
|
270 |
+
"Is the moon closer to earth or the sun?",
|
271 |
+
"How good are the apple pie cookies?",
|
272 |
+
"What tools do I need for the Nutella Ice Cream?",
|
273 |
+
"My bowl is broken, can I still make Nutella Ice Cream? Answer as a yes/no."
|
274 |
+
]
|
275 |
+
gr.Examples(examples, [inp])
|
276 |
+
with gr.Column():
|
277 |
+
out = gr.TextArea(label="ReAct Answer", placeholder="The answer will go here...")
|
278 |
+
|
279 |
+
btn.click(fn=ask_query, inputs=inp, outputs=out)
|
280 |
+
|
281 |
demo.launch(show_error=True)
|
282 |
|
283 |
|
demo-tools-1.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
@@ -37,7 +37,7 @@
|
|
37 |
},
|
38 |
{
|
39 |
"cell_type": "code",
|
40 |
-
"execution_count":
|
41 |
"metadata": {},
|
42 |
"outputs": [
|
43 |
{
|
@@ -46,7 +46,7 @@
|
|
46 |
"False"
|
47 |
]
|
48 |
},
|
49 |
-
"execution_count":
|
50 |
"metadata": {},
|
51 |
"output_type": "execute_result"
|
52 |
}
|
@@ -64,7 +64,7 @@
|
|
64 |
},
|
65 |
{
|
66 |
"cell_type": "code",
|
67 |
-
"execution_count":
|
68 |
"metadata": {},
|
69 |
"outputs": [],
|
70 |
"source": [
|
@@ -109,7 +109,7 @@
|
|
109 |
},
|
110 |
{
|
111 |
"cell_type": "code",
|
112 |
-
"execution_count":
|
113 |
"metadata": {},
|
114 |
"outputs": [],
|
115 |
"source": [
|
@@ -209,7 +209,7 @@
|
|
209 |
},
|
210 |
{
|
211 |
"cell_type": "code",
|
212 |
-
"execution_count":
|
213 |
"metadata": {},
|
214 |
"outputs": [],
|
215 |
"source": [
|
@@ -245,7 +245,7 @@
|
|
245 |
},
|
246 |
{
|
247 |
"cell_type": "code",
|
248 |
-
"execution_count":
|
249 |
"metadata": {},
|
250 |
"outputs": [
|
251 |
{
|
@@ -302,7 +302,7 @@
|
|
302 |
},
|
303 |
{
|
304 |
"cell_type": "code",
|
305 |
-
"execution_count":
|
306 |
"metadata": {},
|
307 |
"outputs": [],
|
308 |
"source": [
|
@@ -345,7 +345,96 @@
|
|
345 |
},
|
346 |
{
|
347 |
"cell_type": "code",
|
348 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
"metadata": {},
|
350 |
"outputs": [
|
351 |
{
|
@@ -353,6 +442,10 @@
|
|
353 |
"output_type": "stream",
|
354 |
"text": [
|
355 |
"c:\\sc\\ai\\rag-demo-1\\.venv\\lib\\site-packages\\gradio\\interface.py:330: UserWarning: The `allow_flagging` parameter in `Interface` nowtakes a string value ('auto', 'manual', or 'never'), not a boolean. Setting parameter to: 'never'.\n",
|
|
|
|
|
|
|
|
|
356 |
" warnings.warn(\n"
|
357 |
]
|
358 |
},
|
@@ -360,7 +453,7 @@
|
|
360 |
"name": "stdout",
|
361 |
"output_type": "stream",
|
362 |
"text": [
|
363 |
-
"Running on local URL: http://127.0.0.1:
|
364 |
"\n",
|
365 |
"To create a public link, set `share=True` in `launch()`.\n"
|
366 |
]
|
@@ -368,7 +461,7 @@
|
|
368 |
{
|
369 |
"data": {
|
370 |
"text/html": [
|
371 |
-
"<div><iframe src=\"http://127.0.0.1:
|
372 |
],
|
373 |
"text/plain": [
|
374 |
"<IPython.core.display.HTML object>"
|
@@ -381,7 +474,7 @@
|
|
381 |
"data": {
|
382 |
"text/plain": []
|
383 |
},
|
384 |
-
"execution_count":
|
385 |
"metadata": {},
|
386 |
"output_type": "execute_result"
|
387 |
}
|
@@ -408,7 +501,7 @@
|
|
408 |
" resp += response['output']\n",
|
409 |
" return resp\n",
|
410 |
"\n",
|
411 |
-
"demo = gr.Interface(fn=ask_query, inputs
|
412 |
"#gr.Markdown(\"# Hello there\")\n",
|
413 |
"#gr.Examples(\"text\", \"text\")\n",
|
414 |
"demo.launch(show_error=True)"
|
@@ -416,7 +509,7 @@
|
|
416 |
},
|
417 |
{
|
418 |
"cell_type": "code",
|
419 |
-
"execution_count":
|
420 |
"metadata": {},
|
421 |
"outputs": [
|
422 |
{
|
@@ -426,23 +519,12 @@
|
|
426 |
"\n",
|
427 |
"\n",
|
428 |
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
429 |
-
"\u001b[32;1m\u001b[1;
|
430 |
-
"
|
431 |
-
"\n",
|
432 |
-
"\u001b[1m
|
433 |
-
"\n",
|
434 |
-
"\n",
|
435 |
-
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
436 |
-
"\u001b[32;1m\u001b[1;3mThe question is asking for the tools needed to bake a chicken, not a specific recipe. However, I can use the Chicken Recipes tool to find a recipe for baked chicken, and then use the Get a Recipe tool to find out what tools are needed for that recipe.\n",
|
437 |
-
"Action: Chicken Recipes tool\n",
|
438 |
-
"Action Input: \"baked chicken\"\u001b[0m\n",
|
439 |
-
"Observation: \u001b[36;1m\u001b[1;3m[{'title': 'Crispy Roasted Chicken', 'url': 'https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/'}, {'title': 'Roasted Spatchcocked Chicken With Potatoes', 'url': 'https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/'}, {'title': 'Easy Baked Chicken Thighs', 'url': 'https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/'}, {'title': 'Crispy Baked Chicken Thighs', 'url': 'https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/'}, {'title': 'Crispy and Tender Baked Chicken Thighs', 'url': 'https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/'}, {'title': 'Million Dollar Chicken', 'url': 'https://www.allrecipes.com/recipe/233953/million-dollar-chicken/'}, {'title': 'Simple Whole Roasted Chicken', 'url': 'https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/'}, {'title': 'Beer Can Chicken', 'url': 'https://www.allrecipes.com/recipe/214618/beer-can-chicken/'}, {'title': 'Air Fryer Chicken Thighs', 'url': 'https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/'}, {'title': 'Happy Roast Chicken', 'url': 'https://www.allrecipes.com/recipe/214478/happy-roast-chicken/'}]\u001b[0m\n",
|
440 |
-
"Thought:\u001b[32;1m\u001b[1;3mI have found a list of chicken recipes. I will choose the first one, 'Crispy Roasted Chicken', and use the Get a Recipe tool to find out what tools are needed for this recipe.\n",
|
441 |
-
"Action: Get a Recipe tool\n",
|
442 |
-
"Action Input: 'https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/'\u001b[0m\n",
|
443 |
-
"Observation: \u001b[38;5;200m\u001b[1;3m{'@context': 'http://schema.org', '@type': ['Recipe'], 'headline': 'Crispy Roasted Chicken', 'datePublished': '2014-08-26T18:22:55.000-04:00', 'dateModified': '2023-01-30T04:44:54.000-05:00', 'author': [{'@type': 'Person', 'name': 'Doc Simonson', 'url': 'https://www.allrecipes.com/cook/docsimonson'}], 'description': 'This roasted half chicken is prepared Bavarian-style with spices and herbs, including caraway, sage, fennel, garlic, rosemary, coriander, and paprika.', 'name': 'Crispy Roasted Chicken', 'aggregateRating': {'@type': 'AggregateRating', 'ratingValue': '4.7', 'ratingCount': '134'}, 'cookTime': 'PT60M', 'nutrition': {'@type': 'NutritionInformation', 'calories': '495 kcal', 'carbohydrateContent': '3 g', 'cholesterolContent': '129 mg', 'fiberContent': '1 g', 'proteinContent': '42 g', 'saturatedFatContent': '8 g', 'sodiumContent': '446 mg', 'sugarContent': '1 g', 'fatContent': '35 g', 'unsaturatedFatContent': '0 g'}, 'prepTime': 'PT20M', 'recipeCategory': ['Dinner', 'Drink'], 'recipeCuisine': ['German'], 'recipeIngredient': ['1 teaspoon kosher salt', '0.5 teaspoon caraway seeds', '0.5 teaspoon dried sage', '0.25 teaspoon fennel seeds', '0.25 teaspoon coriander seeds', '0.25 teaspoon dried rosemary', '2 tablespoons paprika', '2 teaspoons garlic powder', '2 teaspoons all-purpose flour', '1 teaspoon onion powder', '5 tablespoons vegetable oil', '1 (4 pound) broiler-fryer chicken, cut in half lengthwise'], 'recipeInstructions': [{'@type': 'HowToStep', 'text': 'Preheat the oven to 425 degrees F (220 degrees C).'}, {'@type': 'HowToStep', 'text': 'Combine kosher salt, caraway, sage, fennel, coriander, and rosemary in a spice grinder or mortar. Grind to a coarse powder. Transfer spice mixture to a bowl; stir in paprika, garlic powder, flour, and onion powder. Mix in vegetable oil to make a smooth paste.'}, {'@type': 'HowToStep', 'text': 'Pat chicken halves dry with paper towels and tuck wing tips behind the back. Brush spice paste onto chicken halves, coating all sides and seasoning under wings and legs. Place chicken halves, skin-sides up, in a baking dish or roasting pan, leaving space around chickens so halves aren't touching.'}, {'@type': 'HowToStep', 'text': 'Roast in the preheated oven until no longer pink at the bone and the juices run clear, about 1 hour. An instant-read thermometer inserted into the thickest part of the thigh, near the bone, should read 165 degrees F (74 degrees C). Remove from the oven and let rest for 10 minutes before slicing.'}], 'recipeYield': ['6'], 'totalTime': 'PT90M', 'about': []}\u001b[0m\n",
|
444 |
-
"Thought:\u001b[32;1m\u001b[1;3mThe recipe provides a list of instructions which mention the tools needed to bake the chicken.\n",
|
445 |
-
"Final Answer: The tools needed to bake a chicken according to the 'Crispy Roasted Chicken' recipe are: an oven, a spice grinder or mortar, a bowl, a brush, a baking dish or roasting pan, paper towels, and an instant-read thermometer.\u001b[0m\n",
|
446 |
"\n",
|
447 |
"\u001b[1m> Finished chain.\u001b[0m\n"
|
448 |
]
|
@@ -498,6 +580,57 @@
|
|
498 |
"# # #gr.Examples(\"text\", \"text\")\n",
|
499 |
"# # demo.launch(show_error=True)"
|
500 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
}
|
502 |
],
|
503 |
"metadata": {
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 278,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
|
|
37 |
},
|
38 |
{
|
39 |
"cell_type": "code",
|
40 |
+
"execution_count": 279,
|
41 |
"metadata": {},
|
42 |
"outputs": [
|
43 |
{
|
|
|
46 |
"False"
|
47 |
]
|
48 |
},
|
49 |
+
"execution_count": 279,
|
50 |
"metadata": {},
|
51 |
"output_type": "execute_result"
|
52 |
}
|
|
|
64 |
},
|
65 |
{
|
66 |
"cell_type": "code",
|
67 |
+
"execution_count": 280,
|
68 |
"metadata": {},
|
69 |
"outputs": [],
|
70 |
"source": [
|
|
|
109 |
},
|
110 |
{
|
111 |
"cell_type": "code",
|
112 |
+
"execution_count": 281,
|
113 |
"metadata": {},
|
114 |
"outputs": [],
|
115 |
"source": [
|
|
|
209 |
},
|
210 |
{
|
211 |
"cell_type": "code",
|
212 |
+
"execution_count": 282,
|
213 |
"metadata": {},
|
214 |
"outputs": [],
|
215 |
"source": [
|
|
|
245 |
},
|
246 |
{
|
247 |
"cell_type": "code",
|
248 |
+
"execution_count": 283,
|
249 |
"metadata": {},
|
250 |
"outputs": [
|
251 |
{
|
|
|
302 |
},
|
303 |
{
|
304 |
"cell_type": "code",
|
305 |
+
"execution_count": 284,
|
306 |
"metadata": {},
|
307 |
"outputs": [],
|
308 |
"source": [
|
|
|
345 |
},
|
346 |
{
|
347 |
"cell_type": "code",
|
348 |
+
"execution_count": 309,
|
349 |
+
"metadata": {},
|
350 |
+
"outputs": [
|
351 |
+
{
|
352 |
+
"name": "stdout",
|
353 |
+
"output_type": "stream",
|
354 |
+
"text": [
|
355 |
+
"Running on local URL: http://127.0.0.1:7923\n",
|
356 |
+
"\n",
|
357 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
358 |
+
]
|
359 |
+
},
|
360 |
+
{
|
361 |
+
"data": {
|
362 |
+
"text/html": [
|
363 |
+
"<div><iframe src=\"http://127.0.0.1:7923/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
364 |
+
],
|
365 |
+
"text/plain": [
|
366 |
+
"<IPython.core.display.HTML object>"
|
367 |
+
]
|
368 |
+
},
|
369 |
+
"metadata": {},
|
370 |
+
"output_type": "display_data"
|
371 |
+
},
|
372 |
+
{
|
373 |
+
"data": {
|
374 |
+
"text/plain": []
|
375 |
+
},
|
376 |
+
"execution_count": 309,
|
377 |
+
"metadata": {},
|
378 |
+
"output_type": "execute_result"
|
379 |
+
}
|
380 |
+
],
|
381 |
+
"source": [
|
382 |
+
"import gradio as gr\n",
|
383 |
+
"\n",
|
384 |
+
"def ask_query(query):\n",
|
385 |
+
" \n",
|
386 |
+
" # LLM \n",
|
387 |
+
" llm = ChatOpenAI(temperature=0, model_name='gpt-4') # 'gpt-3.5-turbo'\n",
|
388 |
+
" agent = initialize_agent(agent=\"zero-shot-react-description\", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)\n",
|
389 |
+
" system = \"If the answer is not in the tools or context passed to you then don't answer. \\nIf you don't know the answer then say so.\" \n",
|
390 |
+
" response = agent({\"input\": f\"{system} {query}\"})\n",
|
391 |
+
"\n",
|
392 |
+
" # Show response \n",
|
393 |
+
" stepsDict = json.loads(dumps(response[\"intermediate_steps\"], pretty=True))\n",
|
394 |
+
" resp = 'Below are the steps the agent took to get to the Final Answer. \\n\"Thought\" is the LLMs internal dialogue, \\n\"Action\" is the tool it will use to fetch the next piece of information. \\n\"Action Input\" is the input it passes the tool to fetch this information. \\n\"Action Response\" is what was returned from the tool to the LLM at that given step. '\n",
|
395 |
+
" resp += '\\n\\n'\n",
|
396 |
+
" resp += 'Steps to solve answer using ReAct\\n'\n",
|
397 |
+
" for i in range(len(stepsDict)):\n",
|
398 |
+
" resp += '##########################################\\n'\n",
|
399 |
+
" resp += f'Step: {i+1} of {len(stepsDict)}\\n'\n",
|
400 |
+
" resp += f\"Thought: {stepsDict[i][0]['kwargs']['log']}\\n\"\n",
|
401 |
+
" resp += 'Below is what the tool returned...\\n'\n",
|
402 |
+
" resp += f\"Action response: {stepsDict[i][1]}\\n\" \n",
|
403 |
+
" resp += '\\n'\n",
|
404 |
+
"\n",
|
405 |
+
" resp += '\\nFinal Thought:\\n'\n",
|
406 |
+
" resp += response['output']\n",
|
407 |
+
" return resp\n",
|
408 |
+
"\n",
|
409 |
+
"\n",
|
410 |
+
"with gr.Blocks() as demo:\n",
|
411 |
+
" gr.Markdown(\"Start typing below and then click **Run** to see the output.\")\n",
|
412 |
+
" with gr.Row():\n",
|
413 |
+
" with gr.Column():\n",
|
414 |
+
" inp = gr.Textbox(placeholder=\"Type your question here?\", label=\"Question\") \n",
|
415 |
+
" btn = gr.Button(\"Run\") \n",
|
416 |
+
" examples = [\"Can you show tell me what ingredients I need for the first baked chicken recipe?\",\n",
|
417 |
+
" \"Can you show tell me what ingredients I need for the last baked chicken recipe? \",\n",
|
418 |
+
" \"What is the best baked chicken recipe? Please look across all recipes with the word 'baked' in the title\", # There are 3 baked chicken recipes\n",
|
419 |
+
" \"Is there a Chicken recipe that's prepared with an alchohol? And if so how long does it take in total from start time to finish?\",\n",
|
420 |
+
" \"Which is healthier the Caramel Apple Pie Cookies or the beer chicken? Please explain how you got to your answer.\",\n",
|
421 |
+
" \"Is the moon closer to earth or the sun?\",\n",
|
422 |
+
" \"How good are the apple pie cookies?\",\n",
|
423 |
+
" \"What tools do I need for the Nutella Ice Cream?\",\n",
|
424 |
+
" \"My bowl is broken, can I still make Nutella Ice Cream? Answer as a yes/no.\"\n",
|
425 |
+
" ] \n",
|
426 |
+
" gr.Examples(examples, [inp])\n",
|
427 |
+
" with gr.Column():\n",
|
428 |
+
" out = gr.TextArea(label=\"ReAct Answer\", placeholder=\"The answer will go here...\")\n",
|
429 |
+
" \n",
|
430 |
+
" btn.click(fn=ask_query, inputs=inp, outputs=out)\n",
|
431 |
+
" \n",
|
432 |
+
"demo.launch(show_error=True)"
|
433 |
+
]
|
434 |
+
},
|
435 |
+
{
|
436 |
+
"cell_type": "code",
|
437 |
+
"execution_count": 289,
|
438 |
"metadata": {},
|
439 |
"outputs": [
|
440 |
{
|
|
|
442 |
"output_type": "stream",
|
443 |
"text": [
|
444 |
"c:\\sc\\ai\\rag-demo-1\\.venv\\lib\\site-packages\\gradio\\interface.py:330: UserWarning: The `allow_flagging` parameter in `Interface` nowtakes a string value ('auto', 'manual', or 'never'), not a boolean. Setting parameter to: 'never'.\n",
|
445 |
+
" warnings.warn(\n",
|
446 |
+
"c:\\sc\\ai\\rag-demo-1\\.venv\\lib\\site-packages\\gradio\\utils.py:810: UserWarning: Expected 1 arguments for function <function ask_query at 0x00000155E63AAB90>, received 2.\n",
|
447 |
+
" warnings.warn(\n",
|
448 |
+
"c:\\sc\\ai\\rag-demo-1\\.venv\\lib\\site-packages\\gradio\\utils.py:818: UserWarning: Expected maximum 1 arguments for function <function ask_query at 0x00000155E63AAB90>, received 2.\n",
|
449 |
" warnings.warn(\n"
|
450 |
]
|
451 |
},
|
|
|
453 |
"name": "stdout",
|
454 |
"output_type": "stream",
|
455 |
"text": [
|
456 |
+
"Running on local URL: http://127.0.0.1:7906\n",
|
457 |
"\n",
|
458 |
"To create a public link, set `share=True` in `launch()`.\n"
|
459 |
]
|
|
|
461 |
{
|
462 |
"data": {
|
463 |
"text/html": [
|
464 |
+
"<div><iframe src=\"http://127.0.0.1:7906/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
465 |
],
|
466 |
"text/plain": [
|
467 |
"<IPython.core.display.HTML object>"
|
|
|
474 |
"data": {
|
475 |
"text/plain": []
|
476 |
},
|
477 |
+
"execution_count": 289,
|
478 |
"metadata": {},
|
479 |
"output_type": "execute_result"
|
480 |
}
|
|
|
501 |
" resp += response['output']\n",
|
502 |
" return resp\n",
|
503 |
"\n",
|
504 |
+
"demo = gr.Interface(fn=ask_query, inputs=[\"text\", \"text\"], outputs=\"text\", allow_flagging=False)\n",
|
505 |
"#gr.Markdown(\"# Hello there\")\n",
|
506 |
"#gr.Examples(\"text\", \"text\")\n",
|
507 |
"demo.launch(show_error=True)"
|
|
|
509 |
},
|
510 |
{
|
511 |
"cell_type": "code",
|
512 |
+
"execution_count": 286,
|
513 |
"metadata": {},
|
514 |
"outputs": [
|
515 |
{
|
|
|
519 |
"\n",
|
520 |
"\n",
|
521 |
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
522 |
+
"\u001b[32;1m\u001b[1;3mI need to find the apple cookie pie recipe and check its rating.\n",
|
523 |
+
"Action: Dessert Recipes tool\n",
|
524 |
+
"Action Input: None\u001b[0m\n",
|
525 |
+
"Observation: \u001b[33;1m\u001b[1;3m[{'title': 'Chocolate Snack Cake', 'url': 'https://www.allrecipes.com/chocolate-snack-cake-recipe-8350343'}, {'title': 'Charred Spiced Pears with Smoky Vanilla Cherry Sauce', 'url': 'https://www.allrecipes.com/charred-spiced-pears-with-smoky-vanilla-cherry-sauce-recipe-8347080'}, {'title': 'Meringue Topped Banana Pudding', 'url': 'https://www.allrecipes.com/meringue-topped-banana-pudding-recipe-8347040'}, {'title': 'White Chocolate Cinnamon Toast Crunch Bars', 'url': 'https://www.allrecipes.com/white-chocolate-cinnamon-toast-crunch-bars-recipe-7556790'}, {'title': 'Plum Cobbler for Two', 'url': 'https://www.allrecipes.com/plum-cobbler-for-two-recipe-8304143'}, {'title': 'Pumpkin Cheesecake Cookies', 'url': 'https://www.allrecipes.com/pumpkin-cheesecake-cookies-recipe-7972485'}, {'title': 'Chocolate Whipped Cottage Cheese', 'url': 'https://www.allrecipes.com/chocolate-whipped-cottage-cheese-recipe-8303272'}, {'title': 'Nutella Ice Cream', 'url': 'https://www.allrecipes.com/nutella-ice-cream-recipe-7508716'}, {'title': '3-Ingredient Banana Oatmeal Cookies', 'url': 'https://www.allrecipes.com/3-ingredient-banana-oatmeal-cookies-recipe-7972686'}, {'title': 'Caramel Apple Pie Cookies', 'url': 'https://www.allrecipes.com/caramel-apple-pie-cookies-recipe-7642173'}]\u001b[0m\n",
|
526 |
+
"Thought:\u001b[32;1m\u001b[1;3mThe apple cookie pie recipe is not in the list of dessert recipes. I should say so.\n",
|
527 |
+
"Final Answer: I'm sorry, I couldn't find the apple cookie pie recipe.\u001b[0m\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
"\n",
|
529 |
"\u001b[1m> Finished chain.\u001b[0m\n"
|
530 |
]
|
|
|
580 |
"# # #gr.Examples(\"text\", \"text\")\n",
|
581 |
"# # demo.launch(show_error=True)"
|
582 |
]
|
583 |
+
},
|
584 |
+
{
|
585 |
+
"cell_type": "code",
|
586 |
+
"execution_count": 291,
|
587 |
+
"metadata": {},
|
588 |
+
"outputs": [
|
589 |
+
{
|
590 |
+
"name": "stdout",
|
591 |
+
"output_type": "stream",
|
592 |
+
"text": [
|
593 |
+
"Running on local URL: http://127.0.0.1:7908\n",
|
594 |
+
"\n",
|
595 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
596 |
+
]
|
597 |
+
},
|
598 |
+
{
|
599 |
+
"data": {
|
600 |
+
"text/html": [
|
601 |
+
"<div><iframe src=\"http://127.0.0.1:7908/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
602 |
+
],
|
603 |
+
"text/plain": [
|
604 |
+
"<IPython.core.display.HTML object>"
|
605 |
+
]
|
606 |
+
},
|
607 |
+
"metadata": {},
|
608 |
+
"output_type": "display_data"
|
609 |
+
},
|
610 |
+
{
|
611 |
+
"data": {
|
612 |
+
"text/plain": []
|
613 |
+
},
|
614 |
+
"execution_count": 291,
|
615 |
+
"metadata": {},
|
616 |
+
"output_type": "execute_result"
|
617 |
+
}
|
618 |
+
],
|
619 |
+
"source": [
|
620 |
+
"import gradio as gr\n",
|
621 |
+
"def update(name):\n",
|
622 |
+
" return f\"Welcome to Gradio, {name}!\"\n",
|
623 |
+
"\n",
|
624 |
+
"with gr.Blocks() as demo:\n",
|
625 |
+
" gr.Markdown(\"Start typing below and then click **Run** to see the output.\")\n",
|
626 |
+
" with gr.Row():\n",
|
627 |
+
" inp = gr.Textbox(placeholder=\"What is your name?\")\n",
|
628 |
+
" out = gr.Textbox()\n",
|
629 |
+
" btn = gr.Button(\"Run\")\n",
|
630 |
+
" btn.click(fn=update, inputs=inp, outputs=out)\n",
|
631 |
+
"\n",
|
632 |
+
"demo.launch()"
|
633 |
+
]
|
634 |
}
|
635 |
],
|
636 |
"metadata": {
|