Spaces:
Sleeping
Sleeping
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) | |