Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load LLaMA model via Hugging Face pipeline
|
| 5 |
+
# You can swap this with any LLaMA model hosted on Hugging Face
|
| 6 |
+
# Example: "meta-llama/Llama-2-7b-chat-hf" if you're authenticated
|
| 7 |
+
chatbot = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_new_tokens=200)
|
| 8 |
+
|
| 9 |
+
# Disclaimer text
|
| 10 |
+
disclaimer = "⚠️ **Disclaimer:** Doctor Twin is an AI health companion and not a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare provider for any medical concerns."
|
| 11 |
+
|
| 12 |
+
# Simulated response handler
|
| 13 |
+
def doctor_twin(user_input):
|
| 14 |
+
if not user_input.strip():
|
| 15 |
+
return "Hi! Please describe your symptom or health concern so I can help you better."
|
| 16 |
+
|
| 17 |
+
prompt = f"You are Doctor Twin, a friendly virtual health assistant. Greet the user and respond empathetically with general advice. User says: {user_input}"
|
| 18 |
+
|
| 19 |
+
response = chatbot(prompt)[0]['generated_text'].split("User says:")[1].strip()
|
| 20 |
+
|
| 21 |
+
# Basic recommendations (simulated)
|
| 22 |
+
recommendations = []
|
| 23 |
+
if any(word in user_input.lower() for word in ['cold', 'cough', 'flu']):
|
| 24 |
+
recommendations = ["Stay hydrated", "Get plenty of rest", "Use warm fluids", "See a doctor if fever persists more than 3 days"]
|
| 25 |
+
elif "headache" in user_input.lower():
|
| 26 |
+
recommendations = ["Drink water", "Rest in a dark, quiet room", "Avoid screen time", "Consult a doctor if persistent"]
|
| 27 |
+
elif "sleep" in user_input.lower():
|
| 28 |
+
recommendations = ["Maintain regular sleep schedule", "Avoid caffeine before bed", "Try relaxation techniques"]
|
| 29 |
+
|
| 30 |
+
return response, recommendations
|
| 31 |
+
|
| 32 |
+
# Gradio interface
|
| 33 |
+
with gr.Blocks(title="Doctor Twin – Your Friendly Health Companion") as demo:
|
| 34 |
+
gr.Markdown("# 🩺 Doctor Twin – Your Friendly Health Companion")
|
| 35 |
+
gr.Markdown("**Helping you understand symptoms and stay informed – powered by AI.**")
|
| 36 |
+
gr.Markdown(disclaimer)
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
with gr.Column():
|
| 40 |
+
chatbot_input = gr.Textbox(label="Describe your symptoms or concern", placeholder="e.g., I have a sore throat and mild fever...")
|
| 41 |
+
submit_btn = gr.Button("Ask Doctor Twin")
|
| 42 |
+
|
| 43 |
+
with gr.Column():
|
| 44 |
+
chat_output = gr.Textbox(label="Doctor Twin Says", lines=6)
|
| 45 |
+
recommendation_output = gr.HighlightedText(label="Suggested Recommendations", combine_adjacent=True)
|
| 46 |
+
|
| 47 |
+
submit_btn.click(doctor_twin, chatbot_input, outputs=[chat_output, recommendation_output])
|
| 48 |
+
|
| 49 |
+
# Run the app
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|