Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
|
@@ -1,55 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils import Bot
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def
|
| 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 |
-
interface = gr.Interface(
|
| 38 |
-
initialize_bot,
|
| 39 |
-
input_components,
|
| 40 |
-
show_input=False,
|
| 41 |
-
outputs=output_components,
|
| 42 |
-
title="Chat with your Bot",
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
# Define the callback function for the submit button
|
| 46 |
-
def submit_callback(openai_api_key, table_descriptions, text_documents):
|
| 47 |
-
initialize_bot(openai_api_key, table_descriptions, text_documents)
|
| 48 |
-
|
| 49 |
-
# Define the callback function for the submit question button
|
| 50 |
-
def submit_question_callback(question):
|
| 51 |
-
response = generate_response(question)
|
| 52 |
-
return response
|
| 53 |
-
|
| 54 |
-
# Add the callbacks to the interface
|
| 55 |
-
interface.launch(inline=False, submit_button=submit_callback, submit_question_button=submit_question_callback)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils import Bot
|
| 3 |
|
| 4 |
+
def chatbot_interface():
|
| 5 |
+
openai_api_key = gr.inputs.Textbox(label="OpenAI API Key")
|
| 6 |
+
table_descriptions = gr.inputs.Textbox(label="Table Descriptions")
|
| 7 |
+
text_documents = gr.inputs.Textbox(label="Text Documents")
|
| 8 |
+
init_inputs = [openai_api_key, table_descriptions, text_documents]
|
| 9 |
+
|
| 10 |
+
def init_bot(openai_api_key, table_descriptions, text_documents):
|
| 11 |
+
bot = Bot(openai_api_key=openai_api_key, table_descriptions=table_descriptions, text_documents=text_documents)
|
| 12 |
+
return bot
|
| 13 |
+
|
| 14 |
+
chatbot = gr.inputs.Textbox(label="Ask a question")
|
| 15 |
+
submit_init_button = gr.Interface(
|
| 16 |
+
fn=init_bot,
|
| 17 |
+
inputs=init_inputs,
|
| 18 |
+
outputs=None,
|
| 19 |
+
title="Chat with your Bot",
|
| 20 |
+
description="Enter initialization parameters and click submit to start chatting with your bot."
|
| 21 |
+
)
|
| 22 |
+
submit_chat_button = gr.Interface(
|
| 23 |
+
fn=lambda bot, question: bot(question),
|
| 24 |
+
inputs=[gr.inputs.Hidden(), chatbot],
|
| 25 |
+
outputs=gr.outputs.Textbox(label="Bot Response"),
|
| 26 |
+
title="Chat with your Bot",
|
| 27 |
+
description="Type a question and click submit to get a response from your bot."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
return submit_init_button, submit_chat_button
|
| 31 |
+
|
| 32 |
+
submit_init_button, submit_chat_button = chatbot_interface()
|
| 33 |
+
|
| 34 |
+
submit_init_button.launch()
|
| 35 |
+
submit_chat_button.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|