Spaces:
Sleeping
Sleeping
file added
Browse files
app.py
CHANGED
@@ -234,8 +234,8 @@ def customLLMBot(user_input, uploaded_image, chat_history):
|
|
234 |
medical_entities = extract_medical_entities(user_input)
|
235 |
logger.info(f"Extracted medical entities: {medical_entities}")
|
236 |
|
237 |
-
#
|
238 |
-
chat_history.append(
|
239 |
|
240 |
if uploaded_image is not None:
|
241 |
base64_image = encode_image(uploaded_image)
|
@@ -272,8 +272,8 @@ def customLLMBot(user_input, uploaded_image, chat_history):
|
|
272 |
LLM_reply = response.choices[0].message.content
|
273 |
logger.debug(f"LLM reply: {LLM_reply}")
|
274 |
|
275 |
-
#
|
276 |
-
chat_history.append(
|
277 |
messages.append({"role": "assistant", "content": LLM_reply})
|
278 |
|
279 |
audio_file = f"response_{uuid.uuid4().hex}.mp3"
|
@@ -285,36 +285,19 @@ def customLLMBot(user_input, uploaded_image, chat_history):
|
|
285 |
|
286 |
except Exception as e:
|
287 |
logger.error(f"Error in customLLMBot function: {e}")
|
288 |
-
return [
|
289 |
-
|
290 |
# Gradio Interface
|
291 |
def chatbot_ui():
|
292 |
logger.info("Setting up Gradio interface...")
|
293 |
with gr.Blocks() as demo:
|
294 |
-
#
|
295 |
-
demo.css = """
|
296 |
-
.chatbot-container {
|
297 |
-
font-family: Arial, sans-serif;
|
298 |
-
}
|
299 |
-
.user-icon::before {
|
300 |
-
content: "\\f007"; /* Font Awesome user icon */
|
301 |
-
font-family: "Font Awesome 5 Free";
|
302 |
-
margin-right: 8px;
|
303 |
-
}
|
304 |
-
.bot-icon::before {
|
305 |
-
content: "\\f1c0"; /* Font Awesome robot icon */
|
306 |
-
font-family: "Font Awesome 5 Free";
|
307 |
-
margin-right: 8px;
|
308 |
-
}
|
309 |
-
"""
|
310 |
-
|
311 |
-
gr.Markdown("# DermaCare Doctor")
|
312 |
|
313 |
chat_history = gr.State([])
|
314 |
|
315 |
with gr.Row():
|
316 |
with gr.Column(scale=3):
|
317 |
-
chatbot = gr.Chatbot(label="Responses", elem_id="chatbot"
|
318 |
user_input = gr.Textbox(
|
319 |
label="Ask a health-related question",
|
320 |
placeholder="Describe your symptoms...",
|
@@ -327,8 +310,6 @@ def chatbot_ui():
|
|
327 |
clear_btn = gr.Button("Clear")
|
328 |
audio_output = gr.Audio(label="Audio Response")
|
329 |
|
330 |
-
|
331 |
-
|
332 |
with gr.Row():
|
333 |
with gr.Column():
|
334 |
gr.Markdown("### Upload Image for Prediction")
|
|
|
234 |
medical_entities = extract_medical_entities(user_input)
|
235 |
logger.info(f"Extracted medical entities: {medical_entities}")
|
236 |
|
237 |
+
# Append user query to chat history
|
238 |
+
chat_history.append(user_input)
|
239 |
|
240 |
if uploaded_image is not None:
|
241 |
base64_image = encode_image(uploaded_image)
|
|
|
272 |
LLM_reply = response.choices[0].message.content
|
273 |
logger.debug(f"LLM reply: {LLM_reply}")
|
274 |
|
275 |
+
# Append LLM reply to chat history
|
276 |
+
chat_history.append(LLM_reply)
|
277 |
messages.append({"role": "assistant", "content": LLM_reply})
|
278 |
|
279 |
audio_file = f"response_{uuid.uuid4().hex}.mp3"
|
|
|
285 |
|
286 |
except Exception as e:
|
287 |
logger.error(f"Error in customLLMBot function: {e}")
|
288 |
+
return [user_input or "Image uploaded", f"An error occurred: {e}"], None
|
289 |
+
|
290 |
# Gradio Interface
|
291 |
def chatbot_ui():
|
292 |
logger.info("Setting up Gradio interface...")
|
293 |
with gr.Blocks() as demo:
|
294 |
+
gr.Markdown("# Dermacare Chatbot Doctor")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
chat_history = gr.State([])
|
297 |
|
298 |
with gr.Row():
|
299 |
with gr.Column(scale=3):
|
300 |
+
chatbot = gr.Chatbot(label="Responses", elem_id="chatbot")
|
301 |
user_input = gr.Textbox(
|
302 |
label="Ask a health-related question",
|
303 |
placeholder="Describe your symptoms...",
|
|
|
310 |
clear_btn = gr.Button("Clear")
|
311 |
audio_output = gr.Audio(label="Audio Response")
|
312 |
|
|
|
|
|
313 |
with gr.Row():
|
314 |
with gr.Column():
|
315 |
gr.Markdown("### Upload Image for Prediction")
|