Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,83 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
from transformers import pipeline
|
4 |
-
import tensorflow as tf
|
5 |
-
import numpy as np
|
6 |
-
from PIL import Image
|
7 |
-
import random
|
8 |
|
9 |
-
# Load
|
10 |
-
|
11 |
-
|
12 |
-
retina_model =
|
13 |
-
stool_model = tf.keras.models.load_model("stool_microbiome_model.h5") # Gut microbiome detection AI
|
14 |
|
15 |
-
#
|
16 |
-
def
|
17 |
-
|
18 |
-
return f"Condition: {result['label']} (Confidence: {round(result['score'] * 100, 2)}%)"
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
img = Image.open(image).resize((224, 224))
|
23 |
-
img_array = np.array(img) / 255.0
|
24 |
-
img_array = np.expand_dims(img_array, axis=0)
|
25 |
-
|
26 |
-
prediction = stool_model.predict(img_array)
|
27 |
-
class_names = ["Healthy Gut", "Possible Dysbiosis", "Severe Gut Imbalance"]
|
28 |
-
return f"Result: {class_names[np.argmax(prediction)]}"
|
29 |
|
30 |
-
# Retina disease detection function
|
31 |
def analyze_retina(image):
|
32 |
-
|
33 |
-
img_array = np.array(img) / 255.0
|
34 |
-
img_array = np.expand_dims(img_array, axis=0)
|
35 |
-
|
36 |
-
prediction = retina_model.predict(img_array)
|
37 |
-
class_names = ["Normal Retina", "Diabetic Retinopathy", "Glaucoma Detected"]
|
38 |
-
return f"Retina Scan: {class_names[np.argmax(prediction)]}"
|
39 |
-
|
40 |
-
# Emotion-to-disease analysis
|
41 |
-
def emotion_to_disease(emotion_text):
|
42 |
-
emotions = {
|
43 |
-
"stress": "Long-term stress can cause high blood pressure, anxiety, and digestive issues.",
|
44 |
-
"anger": "Frequent anger can increase heart disease risk.",
|
45 |
-
"happiness": "A positive mindset improves overall well-being!"
|
46 |
-
}
|
47 |
-
detected_emotion = emotion_model(emotion_text)[0]['label']
|
48 |
-
return emotions.get(detected_emotion.lower(), "No specific health risks detected.")
|
49 |
|
50 |
# Gradio UI
|
51 |
-
with gr.Blocks(
|
52 |
-
gr.Markdown("#
|
53 |
-
|
54 |
-
|
55 |
-
with gr.Row():
|
56 |
-
symptom_input = gr.Textbox(label="Enter symptoms")
|
57 |
-
symptom_output = gr.Textbox(label="Diagnosis Result", interactive=False)
|
58 |
-
gr.Button("Diagnose").click(diagnose, inputs=symptom_input, outputs=symptom_output)
|
59 |
-
|
60 |
-
# Gut microbiome (stool analysis)
|
61 |
-
with gr.Row():
|
62 |
-
stool_input = gr.Image(label="Upload Stool Image")
|
63 |
-
stool_output = gr.Textbox(label="Microbiome Analysis", interactive=False)
|
64 |
-
gr.Button("Analyze Stool").click(analyze_stool, inputs=stool_input, outputs=stool_output)
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
retina_output = gr.Textbox(label="Retina Disease Detection", interactive=False)
|
70 |
-
gr.Button("Analyze Retina").click(analyze_retina, inputs=retina_input, outputs=retina_output)
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
emotion_output = gr.Textbox(label="Health Analysis", interactive=False)
|
76 |
-
gr.Button("Analyze Emotion").click(emotion_to_disease, inputs=emotion_input, outputs=emotion_output)
|
77 |
|
78 |
-
|
|
|
|
|
79 |
|
80 |
# Launch the app
|
81 |
-
|
82 |
|
83 |
|
|
|
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 |
|