Nadera03 commited on
Commit
e5dac7e
·
verified ·
1 Parent(s): b8cd77a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -26
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="bert-base-uncased")
6
- microbiome_model = pipeline("text-generation", model="microsoft/BioGPT-Large")
7
- retina_model = pipeline("image-classification", model="microsoft/resnet-50")
 
8
 
9
- # Define functions
10
- def diagnose_emotion(text):
11
- return emotion_model(text)
 
 
 
 
 
 
 
 
 
12
 
13
- def analyze_microbiome(symptoms):
14
- return microbiome_model(symptoms)
 
 
 
15
 
16
- def analyze_retina(image):
17
- return retina_model(image)
 
 
 
 
 
 
18
 
19
- # Gradio UI
20
  with gr.Blocks() as app:
21
- gr.Markdown("# Diagnosify-AI - AI Medical Assistant")
22
- text_input = gr.Textbox(label="Enter Symptoms")
23
- image_input = gr.Image(type="pil", label="Upload Retina Scan")
 
 
 
24
 
25
- btn1 = gr.Button("Diagnose Emotion-based Disease")
26
- btn2 = gr.Button("Analyze Gut Health")
27
- btn3 = gr.Button("Detect Retinal Disease")
 
 
28
 
29
- output1 = gr.Textbox(label="Diagnosis")
30
- output2 = gr.Textbox(label="Microbiome Analysis")
31
- output3 = gr.Label(label="Retinal Disease Prediction")
 
 
32
 
33
- btn1.click(diagnose_emotion, inputs=text_input, outputs=output1)
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