Upload 3 files
Browse filesHealthAI combines advanced AI with holistic health knowledge, making healthcare accessible and user-friendly. Whether you’re curious about your symptoms or looking for natural treatment options, HealthAI is your go-to digital health assistant.
- README.md +31 -14
- app.py +98 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,14 +1,31 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 🤖 HealthAI
|
2 |
+
|
3 |
+
HealthAI is an intelligent healthcare assistant powered by IBM Granite-3B-Instruct model. It offers:
|
4 |
+
|
5 |
+
- 🩺 Disease prediction from symptoms
|
6 |
+
- 🌿 Home remedy suggestions
|
7 |
+
- 🛡️ Preventive health advice
|
8 |
+
- 🥗 Diet recommendations
|
9 |
+
- 🆘 First aid instructions
|
10 |
+
|
11 |
+
## 🔧 How to Run
|
12 |
+
|
13 |
+
1. Install dependencies:
|
14 |
+
```
|
15 |
+
pip install -r requirements.txt
|
16 |
+
```
|
17 |
+
|
18 |
+
2. Run the app:
|
19 |
+
```
|
20 |
+
python app.py
|
21 |
+
```
|
22 |
+
|
23 |
+
3. Or deploy to Hugging Face with:
|
24 |
+
```
|
25 |
+
gradio deploy
|
26 |
+
```
|
27 |
+
|
28 |
+
## 💡 Powered by:
|
29 |
+
- IBM Granite 3.3B model
|
30 |
+
- Hugging Face Transformers
|
31 |
+
- Gradio for UI
|
app.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# ✅ Install dependencies first
|
3 |
+
# pip install transformers accelerate gradio translate
|
4 |
+
|
5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
6 |
+
import gradio as gr
|
7 |
+
from translate import Translator
|
8 |
+
|
9 |
+
# Load IBM Granite model
|
10 |
+
model_id = "ibm-granite/granite-3.3-2b-instruct"
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
13 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
14 |
+
|
15 |
+
# Translate helpers
|
16 |
+
def translate_to_english(text, lang_code):
|
17 |
+
if lang_code != "en":
|
18 |
+
translator = Translator(from_lang=lang_code, to_lang="en")
|
19 |
+
return translator.translate(text)
|
20 |
+
return text
|
21 |
+
|
22 |
+
def translate_to_user_lang(text, lang_code):
|
23 |
+
if lang_code != "en":
|
24 |
+
translator = Translator(from_lang="en", to_lang=lang_code)
|
25 |
+
return translator.translate(text)
|
26 |
+
return text
|
27 |
+
|
28 |
+
# Core functions
|
29 |
+
def identify_disease(symptoms, lang_code="en"):
|
30 |
+
symptoms_en = translate_to_english(symptoms, lang_code)
|
31 |
+
prompt = f"You are a medical assistant. A user reports these symptoms: {symptoms_en}. What possible disease or condition could this indicate?"
|
32 |
+
output = generator(prompt, max_new_tokens=150, do_sample=True)[0]["generated_text"]
|
33 |
+
result = output[len(prompt):].strip()
|
34 |
+
return translate_to_user_lang(result, lang_code)
|
35 |
+
|
36 |
+
def suggest_remedy(disease, lang_code="en"):
|
37 |
+
disease_en = translate_to_english(disease, lang_code)
|
38 |
+
prompt = f"Suggest effective natural home remedies for treating {disease_en}."
|
39 |
+
output = generator(prompt, max_new_tokens=150, do_sample=True)[0]["generated_text"]
|
40 |
+
result = output[len(prompt):].strip()
|
41 |
+
return translate_to_user_lang(result, lang_code)
|
42 |
+
|
43 |
+
def preventive_measures(disease, lang_code="en"):
|
44 |
+
disease_en = translate_to_english(disease, lang_code)
|
45 |
+
prompt = f"What are the best preventive measures to avoid {disease_en}?"
|
46 |
+
output = generator(prompt, max_new_tokens=150, do_sample=True)[0]["generated_text"]
|
47 |
+
result = output[len(prompt):].strip()
|
48 |
+
return translate_to_user_lang(result, lang_code)
|
49 |
+
|
50 |
+
def diet_recommendations(disease, lang_code="en"):
|
51 |
+
disease_en = translate_to_english(disease, lang_code)
|
52 |
+
prompt = f"Suggest a healthy diet plan for someone suffering from {disease_en}."
|
53 |
+
output = generator(prompt, max_new_tokens=150, do_sample=True)[0]["generated_text"]
|
54 |
+
result = output[len(prompt):].strip()
|
55 |
+
return translate_to_user_lang(result, lang_code)
|
56 |
+
|
57 |
+
def first_aid_advice(condition, lang_code="en"):
|
58 |
+
condition_en = translate_to_english(condition, lang_code)
|
59 |
+
prompt = f"What first aid steps should be taken immediately for {condition_en}?"
|
60 |
+
output = generator(prompt, max_new_tokens=150, do_sample=True)[0]["generated_text"]
|
61 |
+
result = output[len(prompt):].strip()
|
62 |
+
return translate_to_user_lang(result, lang_code)
|
63 |
+
|
64 |
+
# Gradio UI
|
65 |
+
with gr.Blocks() as demo:
|
66 |
+
gr.Markdown("## 🤖 HealthAI - Your Intelligent Healthcare Assistant")
|
67 |
+
|
68 |
+
with gr.Tab("🩺 Symptoms Identifier"):
|
69 |
+
symptoms_input = gr.Textbox(label="Enter your symptoms")
|
70 |
+
disease_output = gr.Textbox(label="Predicted Disease")
|
71 |
+
btn1 = gr.Button("Identify Disease")
|
72 |
+
btn1.click(fn=identify_disease, inputs=symptoms_input, outputs=disease_output)
|
73 |
+
|
74 |
+
with gr.Tab("🌿 Home Remedies"):
|
75 |
+
disease_input = gr.Textbox(label="Enter disease name")
|
76 |
+
remedy_output = gr.Textbox(label="Suggested Home Remedy")
|
77 |
+
btn2 = gr.Button("Get Remedy")
|
78 |
+
btn2.click(fn=suggest_remedy, inputs=disease_input, outputs=remedy_output)
|
79 |
+
|
80 |
+
with gr.Tab("🛡️ Preventive Measures"):
|
81 |
+
prevent_input = gr.Textbox(label="Enter disease name")
|
82 |
+
prevent_output = gr.Textbox(label="Preventive Measures")
|
83 |
+
btn3 = gr.Button("Get Advice")
|
84 |
+
btn3.click(fn=preventive_measures, inputs=prevent_input, outputs=prevent_output)
|
85 |
+
|
86 |
+
with gr.Tab("🥗 Diet Recommendations"):
|
87 |
+
diet_input = gr.Textbox(label="Enter disease name")
|
88 |
+
diet_output = gr.Textbox(label="Recommended Diet")
|
89 |
+
btn4 = gr.Button("Get Diet Plan")
|
90 |
+
btn4.click(fn=diet_recommendations, inputs=diet_input, outputs=diet_output)
|
91 |
+
|
92 |
+
with gr.Tab("🆘 First Aid Help"):
|
93 |
+
first_aid_input = gr.Textbox(label="Enter medical condition or emergency")
|
94 |
+
first_aid_output = gr.Textbox(label="First Aid Advice")
|
95 |
+
btn5 = gr.Button("Get First Aid")
|
96 |
+
btn5.click(fn=first_aid_advice, inputs=first_aid_input, outputs=first_aid_output)
|
97 |
+
|
98 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
accelerate
|
3 |
+
gradio
|
4 |
+
translate
|
5 |
+
torch
|