Spaces:
Sleeping
Sleeping
modified
Browse files
app.py
CHANGED
@@ -21,6 +21,10 @@ logger.addHandler(file_handler)
|
|
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,13 +38,10 @@ def encode_image(uploaded_image):
|
|
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,17 +95,19 @@ def customLLMBot(user_input, uploaded_image):
|
|
94 |
tts.save(audio_file)
|
95 |
logger.info(f"Audio response saved as {audio_file}")
|
96 |
|
97 |
-
# Return
|
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 [("
|
104 |
|
105 |
|
106 |
# Gradio Interface
|
107 |
def chatbot_ui():
|
|
|
|
|
108 |
with gr.Blocks() as demo:
|
109 |
gr.Markdown("# Healthcare Chatbot Doctor")
|
110 |
|
@@ -127,7 +130,7 @@ def chatbot_ui():
|
|
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
|
@@ -157,4 +160,4 @@ def chatbot_ui():
|
|
157 |
# Launch the interface
|
158 |
chatbot_ui().launch(server_name="0.0.0.0", server_port=7860)
|
159 |
|
160 |
-
#chatbot_ui().launch(server_name="localhost", server_port=7860)
|
|
|
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 |
raise
|
39 |
|
40 |
# Function to handle text and image inputs
|
41 |
+
def customLLMBot(user_input, uploaded_image, chat_history):
|
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 |
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 [(user_input or "Image uploaded", f"An error occurred: {e}")], None
|
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 |
# Define actions
|
131 |
def handle_submit(user_query, image):
|
132 |
logger.info("User submitted a query.")
|
133 |
+
response, audio = customLLMBot(user_query, image, chat_history)
|
134 |
return response, audio, ""
|
135 |
|
136 |
# Submit on pressing Enter key
|
|
|
160 |
# Launch the interface
|
161 |
chatbot_ui().launch(server_name="0.0.0.0", server_port=7860)
|
162 |
|
163 |
+
#chatbot_ui().launch(server_name="localhost", server_port=7860)
|