Spaces:
Running
Running
File size: 4,374 Bytes
adaea7c 63ae673 adaea7c 63ae673 986fa13 1230938 cf2b422 1230938 986fa13 cf2b422 33d21bf adaea7c 986fa13 adaea7c 986fa13 adaea7c 5f3a430 986fa13 33d21bf 986fa13 adaea7c |
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 |
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"---\n",
"description: Gradio app.py\n",
"output-file: app.html\n",
"title: app\n",
"\n",
"---\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"language": "python"
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#: eval: false\n",
"load_dotenv()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Put the chat backend pieces together"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"language": "python"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"skip\n"
]
}
],
"source": [
"def create_demo(bot: ConversationBot):\n",
" sample_images = []\n",
" all_imgs = [f\"{SAMPLE_IMG_DIR}/{img}\" for img in os.listdir(SAMPLE_IMG_DIR)]\n",
" for i, img in enumerate(all_imgs):\n",
" if i in [\n",
" 1,\n",
" 2,\n",
" 3,\n",
" ]:\n",
" sample_images.append(img)\n",
" with gr.Blocks() as demo:\n",
" gr_img = gr.Image(type=\"filepath\")\n",
" btn = gr.Button(value=\"Submit image\")\n",
" ingredients_msg = gr.Text(label=\"Ingredients from image\")\n",
" btn.click(bot.run_img, inputs=[gr_img], outputs=[ingredients_msg])\n",
" gr.Examples(\n",
" examples=sample_images,\n",
" inputs=gr_img,\n",
" )\n",
"\n",
" chatbot = gr.Chatbot(\n",
" value=[(None, bot.ai_prompt_questions[\"ingredients\"].prompt.template)]\n",
" )\n",
"\n",
" msg = gr.Textbox()\n",
" # clear = gr.Button(\"Clear\")\n",
" gr.Markdown(\n",
" \"\"\"\n",
" **🔃Refresh the page to start from scratch🔃** \n",
" \n",
" Recipe search tool powered by the [Edamam API](https://www.edamam.com/) \n",
" \n",
" ![Edamam Logo](https://www.edamam.com/assets/img/small-logo.png)\n",
" \"\"\"\n",
" )\n",
" msg.submit(\n",
" fn=bot.respond, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False\n",
" )\n",
" # clear.click(lambda: None, None, chatbot, queue=False).then(bot.reset)\n",
" return demo"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"language": "python"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Closing server running on port: 7860\n",
"Running on local URL: http://127.0.0.1:7860\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7860/\" 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": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#| eval: false\n",
"if \"demo\" in globals():\n",
" demo.close()\n",
"\n",
"demo = create_demo(\n",
" ConversationBot(\n",
" vegan_ingred_finder=vegan_ingred_finder, img_cap=img_cap, verbose=True\n",
" )\n",
")\n",
"demo.launch()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"language": "python",
"name": "python3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|