Spaces:
Sleeping
Sleeping
CHANGED ORIGINAL APP.PY TO APPeithoutResetButton.py and added new app.py
Browse filesTry to fix : TypeError: gradio_chatbot() takes 1 positional argument but 2 were given
- APPwithoutResetButton.py +36 -0
- app.py +10 -23
APPwithoutResetButton.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# # app.py
|
| 2 |
+
|
| 3 |
+
# import gradio as gr
|
| 4 |
+
# from pipeline import chatbot_response, generate_coherent_response, ChatHistory
|
| 5 |
+
|
| 6 |
+
# # Create a new instance of chat history
|
| 7 |
+
# chat_history = ChatHistory()
|
| 8 |
+
|
| 9 |
+
# # Step 6: Define Gradio Interface for Chatbot
|
| 10 |
+
# def gradio_chatbot(user_query):
|
| 11 |
+
# # Step 7: Retrieve relevant data for the query
|
| 12 |
+
# retrieved_data = chatbot_response(user_query)
|
| 13 |
+
|
| 14 |
+
# # Step 8: Check and verify the query for health/wellness content
|
| 15 |
+
# is_valid = True
|
| 16 |
+
# if is_valid:
|
| 17 |
+
# # Generate a coherent response using Groq's DeepSeek-R1 LLM
|
| 18 |
+
# coherent_response = generate_coherent_response(user_query, retrieved_data, chat_history.get_history())
|
| 19 |
+
# else:
|
| 20 |
+
# coherent_response = "The query does not seem to match health and wellness topics."
|
| 21 |
+
|
| 22 |
+
# # Add the user message and assistant response to the chat history
|
| 23 |
+
# chat_history.add_message("user", user_query)
|
| 24 |
+
# chat_history.add_message("assistant", coherent_response)
|
| 25 |
+
|
| 26 |
+
# # Return the response and the chat history
|
| 27 |
+
# return coherent_response, chat_history.get_history()
|
| 28 |
+
|
| 29 |
+
# # Create the Gradio interface
|
| 30 |
+
# iface = gr.Interface(fn=gradio_chatbot,
|
| 31 |
+
# inputs=gr.Textbox(label="Ask a question"),
|
| 32 |
+
# outputs=[gr.Textbox(label="Chatbot Response"), gr.Textbox(label="Chat History")],
|
| 33 |
+
# title="Wellness Chatbot")
|
| 34 |
+
|
| 35 |
+
# # Launch the Gradio interface
|
| 36 |
+
# iface.launch()
|
app.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
from pipeline import chatbot_response, generate_coherent_response, ChatHistory
|
| 5 |
|
|
@@ -7,24 +5,23 @@ from pipeline import chatbot_response, generate_coherent_response, ChatHistory
|
|
| 7 |
chat_history = ChatHistory()
|
| 8 |
|
| 9 |
# Step 6: Define Gradio Interface for Chatbot
|
| 10 |
-
def gradio_chatbot(user_query):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Step 7: Retrieve relevant data for the query
|
| 12 |
retrieved_data = chatbot_response(user_query)
|
| 13 |
|
| 14 |
# Step 8: Check and verify the query for health/wellness content
|
| 15 |
is_valid = True
|
| 16 |
if is_valid:
|
| 17 |
-
# Generate a coherent response using Groq's
|
| 18 |
-
coherent_response = generate_coherent_response(user_query, retrieved_data,
|
| 19 |
else:
|
| 20 |
coherent_response = "The query does not seem to match health and wellness topics."
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
# # Add the user message and assistant response to the chat history
|
| 24 |
-
# chat_history.add_message("user", user_query)
|
| 25 |
-
# chat_history.add_message("assistant", coherent_response)
|
| 26 |
-
# # Return the response and the chat history
|
| 27 |
-
# return coherent_response, chat_history.get_history()
|
| 28 |
if not history:
|
| 29 |
history = ""
|
| 30 |
if history:
|
|
@@ -32,8 +29,8 @@ def gradio_chatbot(user_query):
|
|
| 32 |
history += f"User: {user_query}\nAssistant: {coherent_response}"
|
| 33 |
|
| 34 |
return coherent_response, history
|
| 35 |
-
|
| 36 |
|
|
|
|
| 37 |
def reset_chat():
|
| 38 |
"""Reset the chat interface."""
|
| 39 |
chat_history.reset()
|
|
@@ -72,14 +69,4 @@ with gr.Blocks(title="Wellness Chatbot") as iface:
|
|
| 72 |
)
|
| 73 |
|
| 74 |
# Launch the Gradio interface
|
| 75 |
-
iface.launch()
|
| 76 |
-
|
| 77 |
-
#OLDER VERSION
|
| 78 |
-
# # Create the Gradio interface
|
| 79 |
-
# iface = gr.Interface(fn=gradio_chatbot,
|
| 80 |
-
# inputs=gr.Textbox(label="Ask a question"),
|
| 81 |
-
# outputs=[gr.Textbox(label="Chatbot Response"), gr.Textbox(label="Chat History")],
|
| 82 |
-
# title="Wellness Chatbot")
|
| 83 |
-
|
| 84 |
-
# # Launch the Gradio interface
|
| 85 |
-
# iface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from pipeline import chatbot_response, generate_coherent_response, ChatHistory
|
| 3 |
|
|
|
|
| 5 |
chat_history = ChatHistory()
|
| 6 |
|
| 7 |
# Step 6: Define Gradio Interface for Chatbot
|
| 8 |
+
def gradio_chatbot(user_query, history):
|
| 9 |
+
# Process query only if it's not empty
|
| 10 |
+
if not user_query.strip():
|
| 11 |
+
return "", history if history else ""
|
| 12 |
+
|
| 13 |
# Step 7: Retrieve relevant data for the query
|
| 14 |
retrieved_data = chatbot_response(user_query)
|
| 15 |
|
| 16 |
# Step 8: Check and verify the query for health/wellness content
|
| 17 |
is_valid = True
|
| 18 |
if is_valid:
|
| 19 |
+
# Generate a coherent response using Groq's model
|
| 20 |
+
coherent_response = generate_coherent_response(user_query, retrieved_data, history)
|
| 21 |
else:
|
| 22 |
coherent_response = "The query does not seem to match health and wellness topics."
|
| 23 |
|
| 24 |
+
# Add the messages to history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if not history:
|
| 26 |
history = ""
|
| 27 |
if history:
|
|
|
|
| 29 |
history += f"User: {user_query}\nAssistant: {coherent_response}"
|
| 30 |
|
| 31 |
return coherent_response, history
|
|
|
|
| 32 |
|
| 33 |
+
# Reset function to clear chat history and response
|
| 34 |
def reset_chat():
|
| 35 |
"""Reset the chat interface."""
|
| 36 |
chat_history.reset()
|
|
|
|
| 69 |
)
|
| 70 |
|
| 71 |
# Launch the Gradio interface
|
| 72 |
+
iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|