Spaces:
Sleeping
Sleeping
File size: 1,431 Bytes
7f3f731 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
from medical_chatbot import ColabBioGPTChatbot
# Instantiate and auto-load the medical data
chatbot = ColabBioGPTChatbot(use_gpu=True, use_8bit=True)
medical_file_uploaded = False
try:
chatbot.load_medical_data("Pediatric_cleaned.txt")
medical_file_uploaded = True
startup_status = "✅ Medical file 'Pediatric_cleaned.txt' loaded at startup. Ready to chat!"
except Exception as e:
startup_status = f"❌ Failed to load 'Pediatric_cleaned.txt': {str(e)}"
def generate_response(user_input):
if not medical_file_uploaded:
return "⚠️ Medical data failed to load. Please check the file and restart the app."
return chatbot.chat(user_input)
with gr.Blocks() as demo:
gr.Markdown("## 🩺 Pediatric Medical Assistant")
gr.Markdown(startup_status)
chatbot_ui = gr.Chatbot(label="🧠 Chat History")
user_input = gr.Textbox(placeholder="Ask a pediatric health question...", lines=2, show_label=False)
submit_btn = gr.Button("Send")
def on_submit(user_message, chat_history):
bot_response = generate_response(user_message)
chat_history.append((user_message, bot_response))
return "", chat_history
user_input.submit(fn=on_submit, inputs=[user_input, chatbot_ui], outputs=[user_input, chatbot_ui])
submit_btn.click(fn=on_submit, inputs=[user_input, chatbot_ui], outputs=[user_input, chatbot_ui])
demo.launch(share=True)
|