Spaces:
Runtime error
Runtime error
File size: 4,640 Bytes
d88c550 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4a6b2b70",
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"\n",
"from buster.chatbot import Chatbot, ChatbotConfig\n",
"\n",
"hf_transformers_cfg = ChatbotConfig(\n",
" documents_file=\"../data/document_embeddings_hf_transformers.tar.gz\",\n",
" unknown_prompt=\"This doesn't seem to be related to the huggingface library. I am not sure how to answer.\",\n",
" embedding_model=\"text-embedding-ada-002\",\n",
" top_k=3,\n",
" thresh=0.7,\n",
" max_chars=3000,\n",
" completion_kwargs={\n",
" \"engine\": \"text-davinci-003\",\n",
" \"max_tokens\": 500,\n",
" },\n",
" separator=\"<br>\",\n",
" link_format=\"markdown\",\n",
" text_after_response=\"I'm a bot 🤖 trained to answer huggingface 🤗 transformers questions. My answers aren't always perfect.\",\n",
" text_before_prompt=\"\"\"You are a slack chatbot assistant answering technical questions about huggingface transformers, a library to train transformers in python.\n",
" Make sure to format your answers in Markdown format, including code block and snippets.\n",
" Do not include any links to urls or hyperlinks in your answers.\n",
"\n",
" If you do not know the answer to a question, or if it is completely irrelevant to the library usage, simply reply with:\n",
"\n",
" 'This doesn't seem to be related to the huggingface library.'\n",
"\n",
" For example:\n",
"\n",
" What is the meaning of life for huggingface?\n",
"\n",
" This doesn't seem to be related to the huggingface library.\n",
"\n",
" Now answer the following question:\n",
" \"\"\",\n",
")\n",
"hf_transformers_chatbot = Chatbot(hf_transformers_cfg)\n",
"\n",
"def chat(question, history):\n",
" history = history or []\n",
" answer = hf_transformers_chatbot.process_input(question)\n",
"\n",
" history.append((question, answer))\n",
" print(history)\n",
" return history, history\n",
"\n",
"\n",
"\n",
"block = gr.Blocks(css=\".gradio-container {background-color: lightgray}\")\n",
"\n",
"with block:\n",
" with gr.Row():\n",
" gr.Markdown(\"<h3><center>Buster 🤖: A Question-Answering Bot for Huggingface 🤗 Transformers </center></h3>\")\n",
"\n",
"\n",
" chatbot = gr.Chatbot()\n",
"\n",
" with gr.Row():\n",
" message = gr.Textbox(\n",
" label=\"What's your question?\",\n",
" placeholder=\"What kind of model should I use for sentiment analysis?\",\n",
" lines=1,\n",
" )\n",
" submit = gr.Button(value=\"Send\", variant=\"secondary\").style(full_width=False)\n",
"\n",
" gr.Examples(\n",
" examples=[\n",
" \"What kind of models should I use for images and text?\",\n",
" \"When should I finetune a model vs. training it form scratch?\",\n",
" \"How can I deploy my trained huggingface model?\",\n",
" \"Can you give me some python code to quickly finetune a model on my sentiment analysis dataset?\",\n",
" ],\n",
" inputs=message,\n",
" )\n",
"\n",
" gr.Markdown(\n",
" \"\"\"This simple application uses GPT to search the huggingface 🤗 transformers docs and answer questions.\n",
" For more info on huggingface transformers view the [full documentation.](https://huggingface.co/docs/transformers/index).\"\"\" \n",
" )\n",
"\n",
"\n",
" gr.HTML(\n",
" \"️<center> Created with ❤️ by @jerpint and @hadrienbertrand\"\n",
" )\n",
"\n",
" state = gr.State()\n",
" agent_state = gr.State()\n",
"\n",
" submit.click(chat, inputs=[message, state], outputs=[chatbot, state])\n",
" message.submit(chat, inputs=[message, state], outputs=[chatbot, state])\n",
"\n",
"\n",
"block.launch(debug=True)"
]
}
],
"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.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|