Spaces:
Runtime error
Runtime error
Update src/chatbot.py
Browse files- src/chatbot.py +4 -7
src/chatbot.py
CHANGED
|
@@ -7,11 +7,9 @@ from .models import route_llm, prompt
|
|
| 7 |
def process_input(user_input, session_id='1'):
|
| 8 |
"""
|
| 9 |
Processes the user input and generates a response using the conversation chain.
|
| 10 |
-
|
| 11 |
Parameters:
|
| 12 |
user_input (str): The user's input message.
|
| 13 |
session_id (str): The session ID for the chat (default is "1").
|
| 14 |
-
|
| 15 |
Returns:
|
| 16 |
str: The generated response from the chatbot.
|
| 17 |
"""
|
|
@@ -35,27 +33,27 @@ def process_input(user_input, session_id='1'):
|
|
| 35 |
|
| 36 |
return response
|
| 37 |
|
| 38 |
-
#
|
| 39 |
def chatbot_interface(user_input, chat_history=None, session_id="1"):
|
| 40 |
"""
|
| 41 |
Interface function for Gradio to handle input and output between the user and the chatbot.
|
| 42 |
-
|
| 43 |
Parameters:
|
| 44 |
user_input (str): The user's input message.
|
| 45 |
session_id (str): The session ID for the chat (default is "1").
|
| 46 |
chat_history (list): List of previous chat messages in the format [[user, bot], ...]
|
| 47 |
-
|
| 48 |
Returns:
|
| 49 |
list: Updated chat history including the new user and bot messages.
|
| 50 |
"""
|
| 51 |
if chat_history is None:
|
| 52 |
chat_history = []
|
| 53 |
|
|
|
|
| 54 |
if user_input == "":
|
| 55 |
bot_response = "Hi there! How can I help you today?"
|
| 56 |
else:
|
| 57 |
bot_response = process_input(user_input, session_id)
|
| 58 |
|
|
|
|
| 59 |
chat_history.append([user_input, bot_response])
|
| 60 |
|
| 61 |
return chat_history
|
|
@@ -68,5 +66,4 @@ def launch_gradio_interface():
|
|
| 68 |
outputs=gr.Chatbot(label="Chat History"),
|
| 69 |
title="AI Chatbot",
|
| 70 |
live=False
|
| 71 |
-
).launch()
|
| 72 |
-
|
|
|
|
| 7 |
def process_input(user_input, session_id='1'):
|
| 8 |
"""
|
| 9 |
Processes the user input and generates a response using the conversation chain.
|
|
|
|
| 10 |
Parameters:
|
| 11 |
user_input (str): The user's input message.
|
| 12 |
session_id (str): The session ID for the chat (default is "1").
|
|
|
|
| 13 |
Returns:
|
| 14 |
str: The generated response from the chatbot.
|
| 15 |
"""
|
|
|
|
| 33 |
|
| 34 |
return response
|
| 35 |
|
| 36 |
+
# Gradio interface function to handle input
|
| 37 |
def chatbot_interface(user_input, chat_history=None, session_id="1"):
|
| 38 |
"""
|
| 39 |
Interface function for Gradio to handle input and output between the user and the chatbot.
|
|
|
|
| 40 |
Parameters:
|
| 41 |
user_input (str): The user's input message.
|
| 42 |
session_id (str): The session ID for the chat (default is "1").
|
| 43 |
chat_history (list): List of previous chat messages in the format [[user, bot], ...]
|
|
|
|
| 44 |
Returns:
|
| 45 |
list: Updated chat history including the new user and bot messages.
|
| 46 |
"""
|
| 47 |
if chat_history is None:
|
| 48 |
chat_history = []
|
| 49 |
|
| 50 |
+
# Greeting at the start of the chat
|
| 51 |
if user_input == "":
|
| 52 |
bot_response = "Hi there! How can I help you today?"
|
| 53 |
else:
|
| 54 |
bot_response = process_input(user_input, session_id)
|
| 55 |
|
| 56 |
+
# Add user input and bot response to chat history
|
| 57 |
chat_history.append([user_input, bot_response])
|
| 58 |
|
| 59 |
return chat_history
|
|
|
|
| 66 |
outputs=gr.Chatbot(label="Chat History"),
|
| 67 |
title="AI Chatbot",
|
| 68 |
live=False
|
| 69 |
+
).launch()
|
|
|