Spaces:
Runtime error
Runtime error
File size: 4,898 Bytes
d88c550 8b5fed9 d88c550 5b7d0e6 d88c550 1f22b14 d88c550 8b5fed9 d88c550 5b7d0e6 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 8b5fed9 d88c550 5b7d0e6 d88c550 5b7d0e6 8b5fed9 5b7d0e6 8b5fed9 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 128 129 130 131 132 133 134 135 136 137 138 139 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4a6b2b70",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import gradio as gr\n",
"\n",
"from buster.chatbot import Chatbot, ChatbotConfig\n",
"\n",
"hf_transformers_cfg = ChatbotConfig(\n",
" documents_file=\"../data/document_embeddings_huggingface.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_words=3000,\n",
" completion_kwargs={\n",
" \"engine\": \"text-davinci-003\",\n",
" \"max_tokens\": 500,\n",
" },\n",
" link_format=\"gradio\",\n",
" response_footnote=\"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",
" \n",
" answer = hf_transformers_chatbot.process_input(question)\n",
" \n",
" # formatting hack for code blocks to render properly every time\n",
" answer = answer.replace(\"```\", \"\\n```\\n\")\n",
"\n",
" history.append((question, answer))\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": "buster",
"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.10.9"
},
"vscode": {
"interpreter": {
"hash": "bfa91706490f6a3314a87f4853806d905e46027cd889e58fcad4739e8600f624"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|