File size: 2,935 Bytes
c417f09
e5dac7e
74caea8
e5dac7e
 
 
c417f09
e5dac7e
 
7056488
e5dac7e
 
74caea8
e5dac7e
 
 
 
 
 
 
 
 
 
 
 
74caea8
e5dac7e
 
 
 
 
c417f09
e5dac7e
 
 
 
 
 
 
 
c417f09
e5dac7e
9e15ad2
e5dac7e
 
 
 
 
 
c417f09
e5dac7e
 
 
 
 
c417f09
e5dac7e
 
fcce0fd
e5dac7e
 
c417f09
e5dac7e
9e15ad2
c417f09
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
import torch
from transformers import pipeline
import cv2
import numpy as np
from PIL import Image

# Load models only once for speed
emotion_model = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion", device=0 if torch.cuda.is_available() else -1)
gut_health_model = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment", device=0 if torch.cuda.is_available() else -1)
retina_model = torch.hub.load("pytorch/vision:v0.10.0", "resnet18", pretrained=True)
retina_model.eval()

# Function: Emotion-based Disease Detection
def detect_disease_from_emotion(text):
    emotions = emotion_model(text)
    emotion_label = emotions[0]['label']
    disease_mapping = {
        "anger": "High blood pressure, Heart Disease",
        "joy": "Generally healthy",
        "sadness": "Depression, Low Immunity",
        "fear": "Anxiety Disorders",
        "surprise": "No major risks"
    }
    return disease_mapping.get(emotion_label, "No specific disease found.")

# Function: Gut Health Analysis
def analyze_gut_health(diet_input):
    result = gut_health_model(diet_input)
    age_range = result[0]['label']
    return f"Your gut microbiome resembles a person in the {age_range} age range."

# Function: Retina Scan Disease Detection
def detect_disease_from_retina(image):
    image = Image.open(image).convert("RGB")
    image = image.resize((224, 224))
    img_tensor = torch.tensor(np.array(image)).float().permute(2, 0, 1).unsqueeze(0) / 255.0
    with torch.no_grad():
        output = retina_model(img_tensor)
    return f"Retina analysis complete. Model confidence score: {output.max().item():.2f}"

# UI Design
with gr.Blocks() as app:
    gr.Markdown("# 🏥 Diagnosify-AI: Your AI Health Assistant")
    with gr.Tab("🧠 Emotion-to-Disease"):
        gr.Markdown("Enter your emotions, and Diagnosify-AI will predict possible health risks.")
        emotion_input = gr.Textbox(label="Describe your current feelings")
        emotion_output = gr.Textbox(label="Possible Health Risks")
        gr.Button("Analyze").click(detect_disease_from_emotion, inputs=emotion_input, outputs=emotion_output)

    with gr.Tab("🍽️ Gut Health Analysis"):
        gr.Markdown("Enter your daily diet to analyze your gut health status.")
        diet_input = gr.Textbox(label="Describe your daily food intake")
        gut_output = gr.Textbox(label="Gut Health Insights")
        gr.Button("Analyze").click(analyze_gut_health, inputs=diet_input, outputs=gut_output)

    with gr.Tab("👁️ Retina Disease Scan"):
        gr.Markdown("Upload an image of your retina for disease analysis.")
        retina_input = gr.Image(type="filepath")  # or "numpy" if needed
        retina_output = gr.Textbox(label="Analysis Result")
        gr.Button("Scan").click(detect_disease_from_retina, inputs=retina_input, outputs=retina_output)

# Launch App
app.launch()