\n",
"panda\n",
"0.3023892641067505\n"
]
}
],
"source": [
"import openai\n",
"import os\n",
"\n",
"with gr.Blocks() as demo:\n",
" gr.HTML(\"\"\"\n",
" Bamboo
\n",
" Bamboo for Image Recognition Demo. Bamboo knows what this object is and what you are doing in a very fine-grain granularity: fratercula arctica (fig.5) and dribbler (fig.2)).
\n",
" Paper: https://arxiv.org/abs/2203.07845
\n",
" Project Website: https://opengvlab.shlab.org.cn/bamboo/home
\n",
" Code and Model: https://github.com/ZhangYuanhan-AI/Bamboo
\n",
" Tips:\n",
" - We use Bamboo and GPT-3 from openai to build this demo
\n",
"
\n",
" \"\"\")\n",
" # history for GPT, conversation for chatbox\n",
" gr_state = gr.State([[],[]])\n",
"\n",
" chatbot = gr.Chatbot(elem_id=\"chatbot\", label=\"Bamboo Chatbot\")\n",
" text_input = gr.Textbox(label=\"Message\", placeholder=\"Send a message\")\n",
" image = gr.inputs.Image()\n",
" with gr.Row():\n",
" submit_btn = gr.Button(\"Submit Text\", interactive=True,variant='primary' )\n",
" reset_btn = gr.Button(\"Reset All\")\n",
" submit_btn_img = gr.Button(\"Submit Img\", interactive=True,variant='primary')\n",
" # clear_btn_img = gr.Button(\"Clear\", interactive=True,variant='primary')\n",
" image_btn = gr.UploadButton(\"Upload Image\", file_types=[\"image\"])\n",
" with gr.Column(scale=0.3, min_width=400):\n",
" max_tokens = gr.Number(\n",
" value=1000, precision=1, interactive=True, label=\"Maximum length of generated text\")\n",
" temperature = gr.Slider(\n",
" minimum=0.0, maximum=1.0, value=0.0, interactive=True, label=\"Diversity of generated text\")\n",
" frequency_penalty = gr.Slider(minimum=-2.0, maximum=2.0, value=0.5,\n",
" step=0.1, interactive=True, label=\"Frequency of generation of repeat tokens\")\n",
" presence_penalty = gr.Slider(minimum=-2.0, maximum=2.0, value=0.0,\n",
" step=0.1, interactive=True, label=\"Frequency of generation of tokens independent of the given prefix\")\n",
"\n",
"\n",
" # image_btn = gr.UploadButton(\"Upload Image\", file_types=[\"image\"])\n",
"\n",
" # image_btn.upload(run_chatbot_with_img, [image_btn,gr_state], [chatbot,gr_state])\n",
"\n",
" text_input.submit(fn=run_chatbot,inputs=[text_input,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state],outputs=[chatbot,gr_state])\n",
" text_input.submit(lambda: \"\", None, text_input)\n",
" submit_btn.click(fn=run_chatbot,inputs=[text_input,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state],outputs=[chatbot,gr_state])\n",
" submit_btn.click(lambda: \"\", None, text_input)\n",
" reset_btn.click(fn=reset,inputs=[],outputs=[chatbot,gr_state])\n",
" submit_btn_img.click(run_chatbot_with_img, [image,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state], [chatbot,gr_state])\n",
" image_btn.upload(run_chatbot_with_img, [image_btn,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state], [chatbot,gr_state])\n",
"\n",
"demo.launch(debug = True)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"is_executing": true
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}