Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,29 +62,32 @@ rag_chain = (
|
|
62 |
| StrOutputParser()
|
63 |
)
|
64 |
|
65 |
-
#
|
66 |
-
def rag_chain_response(
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
|
|
70 |
with gr.Blocks(theme="rawrsor1/Everforest") as app:
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
)
|
79 |
-
with gr.Column(scale=2):
|
80 |
-
response_output = gr.Textbox(
|
81 |
-
lines=10,
|
82 |
-
max_lines=10,
|
83 |
-
)
|
84 |
-
with gr.Row():
|
85 |
-
submit_btn = gr.Button("Submit")
|
86 |
submit_btn.click(
|
87 |
-
rag_chain_response,
|
|
|
|
|
88 |
)
|
89 |
|
|
|
90 |
app.launch(show_error=True)
|
|
|
62 |
| StrOutputParser()
|
63 |
)
|
64 |
|
65 |
+
# Function to handle chatbot interaction
|
66 |
+
def rag_chain_response(messages):
|
67 |
+
# Extract the last user message
|
68 |
+
user_message = messages[-1][0]
|
69 |
+
|
70 |
+
# Generate a response using the RAG chain
|
71 |
+
response = rag_chain.invoke(user_message)
|
72 |
+
|
73 |
+
# Append response to the chat
|
74 |
+
messages.append((user_message, response))
|
75 |
+
return messages
|
76 |
|
77 |
+
# Define the Gradio app
|
78 |
with gr.Blocks(theme="rawrsor1/Everforest") as app:
|
79 |
+
|
80 |
+
|
81 |
+
chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
|
82 |
+
question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
|
83 |
+
submit_btn = gr.Button("Submit")
|
84 |
+
|
85 |
+
# Set up interaction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
submit_btn.click(
|
87 |
+
rag_chain_response, # Function to handle input and generate response
|
88 |
+
inputs=[chatbot], # Pass current conversation state
|
89 |
+
outputs=[chatbot] # Update conversation state
|
90 |
)
|
91 |
|
92 |
+
# Launch the Gradio app
|
93 |
app.launch(show_error=True)
|