Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,32 @@
|
|
1 |
-
import os
|
2 |
-
import requests
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
-
# Hugging Face
|
6 |
-
|
7 |
-
headers = {"Authorization": f"Bearer {os.environ['HF_API_TOKEN']}"}
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
"covid-19": ["fever", "dry cough", "loss of taste or smell", "difficulty breathing"]
|
14 |
-
}
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
}
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
response = requests.post(API_URL, headers=headers, json={"inputs": symptoms})
|
25 |
-
response.raise_for_status()
|
26 |
-
prediction = response.json()
|
27 |
-
return prediction[0]["label"]
|
28 |
-
except Exception:
|
29 |
-
return "Error contacting API."
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
if not user_input.strip():
|
39 |
-
return "Please enter your symptoms."
|
40 |
-
|
41 |
-
if user_input.lower() in disease_symptoms:
|
42 |
-
symptoms = get_symptoms(user_input)
|
43 |
-
advice = provide_assistance(user_input)
|
44 |
-
return f"✅ Known Disease: **{user_input.title()}**\n\nSymptoms: {symptoms}\nAdvice: {advice}"
|
45 |
-
else:
|
46 |
-
disease = identify_disease(user_input)
|
47 |
-
symptoms = get_symptoms(disease)
|
48 |
-
advice = provide_assistance(disease)
|
49 |
-
return f"🧠 Predicted Disease: **{disease}**\n\nSymptoms: {symptoms}\nAdvice: {advice}"
|
50 |
-
|
51 |
-
# Launch Gradio interface
|
52 |
-
gr.Interface(fn=ai_health_assistant,
|
53 |
-
inputs="text",
|
54 |
-
outputs="markdown",
|
55 |
-
title="🩺 AI Health Assistant",
|
56 |
-
description="Enter symptoms or disease name to get predictions and medical guidance.",
|
57 |
-
theme="soft").launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load the model from Hugging Face Hub
|
5 |
+
generator = pipeline("text-generation", model="ibm-granite/granite-3.3-2b-instruct", device_map="auto")
|
|
|
6 |
|
7 |
+
def predict_disease(symptoms):
|
8 |
+
prompt = f"User has the following symptoms: {symptoms}. What is the most probable disease?"
|
9 |
+
result = generator(prompt, max_new_tokens=100, do_sample=True)[0]["generated_text"]
|
10 |
+
return result.split(prompt)[-1].strip()
|
|
|
|
|
11 |
|
12 |
+
def home_remedy(disease):
|
13 |
+
prompt = f"Suggest a natural home remedy for the disease: {disease}."
|
14 |
+
result = generator(prompt, max_new_tokens=100, do_sample=True)[0]["generated_text"]
|
15 |
+
return result.split(prompt)[-1].strip()
|
|
|
16 |
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown("## 🧠 HealthAI")
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
with gr.Tab("🔍 Symptoms Identifier"):
|
21 |
+
symptoms_input = gr.Textbox(label="Enter your symptoms")
|
22 |
+
symptoms_output = gr.Textbox(label="Predicted Disease")
|
23 |
+
symptoms_btn = gr.Button("Predict Disease")
|
24 |
+
symptoms_btn.click(fn=predict_disease, inputs=symptoms_input, outputs=symptoms_output)
|
25 |
|
26 |
+
with gr.Tab("🌿 Home Remedies"):
|
27 |
+
disease_input = gr.Textbox(label="Enter your disease")
|
28 |
+
remedy_output = gr.Textbox(label="Suggested Remedy")
|
29 |
+
remedy_btn = gr.Button("Get Remedy")
|
30 |
+
remedy_btn.click(fn=home_remedy, inputs=disease_input, outputs=remedy_output)
|
31 |
|
32 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|