Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,66 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
3 |
|
4 |
-
# Load models
|
5 |
-
emotion_model = pipeline("text-classification", model="
|
6 |
-
|
7 |
-
retina_model =
|
|
|
8 |
|
9 |
-
#
|
10 |
-
def
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
with gr.Blocks() as app:
|
21 |
-
gr.Markdown("# Diagnosify-AI
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
btn2.click(analyze_microbiome, inputs=text_input, outputs=output2)
|
35 |
-
btn3.click(analyze_retina, inputs=image_input, outputs=output3)
|
36 |
-
|
37 |
-
# Launch the app
|
38 |
app.launch()
|
39 |
|
40 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
from transformers import pipeline
|
4 |
+
import cv2
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
|
8 |
+
# Load models only once for speed
|
9 |
+
emotion_model = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion", device=0 if torch.cuda.is_available() else -1)
|
10 |
+
gut_health_model = pipeline("text-classification", model="mrm8488/bert-mini-finetuned-age-prediction", device=0 if torch.cuda.is_available() else -1)
|
11 |
+
retina_model = torch.hub.load("pytorch/vision:v0.10.0", "resnet18", pretrained=True)
|
12 |
+
retina_model.eval()
|
13 |
|
14 |
+
# Function: Emotion-based Disease Detection
|
15 |
+
def detect_disease_from_emotion(text):
|
16 |
+
emotions = emotion_model(text)
|
17 |
+
emotion_label = emotions[0]['label']
|
18 |
+
disease_mapping = {
|
19 |
+
"anger": "High blood pressure, Heart Disease",
|
20 |
+
"joy": "Generally healthy",
|
21 |
+
"sadness": "Depression, Low Immunity",
|
22 |
+
"fear": "Anxiety Disorders",
|
23 |
+
"surprise": "No major risks"
|
24 |
+
}
|
25 |
+
return disease_mapping.get(emotion_label, "No specific disease found.")
|
26 |
|
27 |
+
# Function: Gut Health Analysis
|
28 |
+
def analyze_gut_health(diet_input):
|
29 |
+
result = gut_health_model(diet_input)
|
30 |
+
age_range = result[0]['label']
|
31 |
+
return f"Your gut microbiome resembles a person in the {age_range} age range."
|
32 |
|
33 |
+
# Function: Retina Scan Disease Detection
|
34 |
+
def detect_disease_from_retina(image):
|
35 |
+
image = Image.open(image).convert("RGB")
|
36 |
+
image = image.resize((224, 224))
|
37 |
+
img_tensor = torch.tensor(np.array(image)).float().permute(2, 0, 1).unsqueeze(0) / 255.0
|
38 |
+
with torch.no_grad():
|
39 |
+
output = retina_model(img_tensor)
|
40 |
+
return f"Retina analysis complete. Model confidence score: {output.max().item():.2f}"
|
41 |
|
42 |
+
# UI Design
|
43 |
with gr.Blocks() as app:
|
44 |
+
gr.Markdown("# 🏥 Diagnosify-AI: Your AI Health Assistant")
|
45 |
+
with gr.Tab("🧠 Emotion-to-Disease"):
|
46 |
+
gr.Markdown("Enter your emotions, and Diagnosify-AI will predict possible health risks.")
|
47 |
+
emotion_input = gr.Textbox(label="Describe your current feelings")
|
48 |
+
emotion_output = gr.Textbox(label="Possible Health Risks")
|
49 |
+
gr.Button("Analyze").click(detect_disease_from_emotion, inputs=emotion_input, outputs=emotion_output)
|
50 |
|
51 |
+
with gr.Tab("🍽️ Gut Health Analysis"):
|
52 |
+
gr.Markdown("Enter your daily diet to analyze your gut health status.")
|
53 |
+
diet_input = gr.Textbox(label="Describe your daily food intake")
|
54 |
+
gut_output = gr.Textbox(label="Gut Health Insights")
|
55 |
+
gr.Button("Analyze").click(analyze_gut_health, inputs=diet_input, outputs=gut_output)
|
56 |
|
57 |
+
with gr.Tab("👁️ Retina Disease Scan"):
|
58 |
+
gr.Markdown("Upload an image of your retina for disease analysis.")
|
59 |
+
retina_input = gr.Image(type="file")
|
60 |
+
retina_output = gr.Textbox(label="Analysis Result")
|
61 |
+
gr.Button("Scan").click(detect_disease_from_retina, inputs=retina_input, outputs=retina_output)
|
62 |
|
63 |
+
# Launch App
|
|
|
|
|
|
|
|
|
64 |
app.launch()
|
65 |
|
66 |
|