Spaces:
Sleeping
Sleeping
modified
Browse files
app.py
CHANGED
|
@@ -21,10 +21,6 @@ logger.addHandler(file_handler)
|
|
| 21 |
# Initialize Groq Client
|
| 22 |
client = Groq(api_key=os.getenv("GROQ_API_KEY_2"))
|
| 23 |
|
| 24 |
-
# client = Groq(
|
| 25 |
-
# api_key="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",
|
| 26 |
-
# )
|
| 27 |
-
|
| 28 |
# Function to encode the image
|
| 29 |
def encode_image(uploaded_image):
|
| 30 |
try:
|
|
@@ -38,10 +34,13 @@ def encode_image(uploaded_image):
|
|
| 38 |
raise
|
| 39 |
|
| 40 |
# Function to handle text and image inputs
|
| 41 |
-
def customLLMBot(user_input, uploaded_image
|
| 42 |
try:
|
| 43 |
logger.info("Processing input...")
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
# Append user input to the chat history
|
| 46 |
chat_history.append(("User", user_input))
|
| 47 |
|
|
@@ -95,19 +94,17 @@ def customLLMBot(user_input, uploaded_image, chat_history):
|
|
| 95 |
tts.save(audio_file)
|
| 96 |
logger.info(f"Audio response saved as {audio_file}")
|
| 97 |
|
| 98 |
-
# Return the chat history and audio file
|
| 99 |
return [(entry[0], entry[1]) for entry in chat_history], audio_file
|
| 100 |
|
| 101 |
except Exception as e:
|
| 102 |
# Handle errors gracefully
|
| 103 |
logger.error(f"Error in customLLMBot function: {e}")
|
| 104 |
-
return [(
|
| 105 |
|
| 106 |
|
| 107 |
# Gradio Interface
|
| 108 |
def chatbot_ui():
|
| 109 |
-
chat_history = [] # Initialize empty chat history
|
| 110 |
-
|
| 111 |
with gr.Blocks() as demo:
|
| 112 |
gr.Markdown("# Healthcare Chatbot Doctor")
|
| 113 |
|
|
@@ -130,7 +127,7 @@ def chatbot_ui():
|
|
| 130 |
# Define actions
|
| 131 |
def handle_submit(user_query, image):
|
| 132 |
logger.info("User submitted a query.")
|
| 133 |
-
response, audio = customLLMBot(user_query, image
|
| 134 |
return response, audio, ""
|
| 135 |
|
| 136 |
# Submit on pressing Enter key
|
|
|
|
| 21 |
# Initialize Groq Client
|
| 22 |
client = Groq(api_key=os.getenv("GROQ_API_KEY_2"))
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Function to encode the image
|
| 25 |
def encode_image(uploaded_image):
|
| 26 |
try:
|
|
|
|
| 34 |
raise
|
| 35 |
|
| 36 |
# Function to handle text and image inputs
|
| 37 |
+
def customLLMBot(user_input, uploaded_image):
|
| 38 |
try:
|
| 39 |
logger.info("Processing input...")
|
| 40 |
|
| 41 |
+
# Initialize a new chat history for the current interaction
|
| 42 |
+
chat_history = []
|
| 43 |
+
|
| 44 |
# Append user input to the chat history
|
| 45 |
chat_history.append(("User", user_input))
|
| 46 |
|
|
|
|
| 94 |
tts.save(audio_file)
|
| 95 |
logger.info(f"Audio response saved as {audio_file}")
|
| 96 |
|
| 97 |
+
# Return only the current chat history (User query + Bot response) and audio file
|
| 98 |
return [(entry[0], entry[1]) for entry in chat_history], audio_file
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
# Handle errors gracefully
|
| 102 |
logger.error(f"Error in customLLMBot function: {e}")
|
| 103 |
+
return [("User", f"An error occurred: {e}")], None
|
| 104 |
|
| 105 |
|
| 106 |
# Gradio Interface
|
| 107 |
def chatbot_ui():
|
|
|
|
|
|
|
| 108 |
with gr.Blocks() as demo:
|
| 109 |
gr.Markdown("# Healthcare Chatbot Doctor")
|
| 110 |
|
|
|
|
| 127 |
# Define actions
|
| 128 |
def handle_submit(user_query, image):
|
| 129 |
logger.info("User submitted a query.")
|
| 130 |
+
response, audio = customLLMBot(user_query, image)
|
| 131 |
return response, audio, ""
|
| 132 |
|
| 133 |
# Submit on pressing Enter key
|