Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,83 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
import random
|
3 |
|
4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def diagnose(symptoms):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
|
14 |
|
15 |
-
#
|
16 |
-
def
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
return "Healthy gut! Your microbiome is balanced."
|
21 |
-
else:
|
22 |
-
return "Gut health status unclear. Maintain a fiber-rich diet."
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
return f"Retina
|
27 |
|
28 |
-
#
|
29 |
-
def
|
30 |
-
|
31 |
-
"
|
32 |
-
"
|
33 |
-
"
|
34 |
}
|
35 |
-
|
|
|
36 |
|
37 |
-
#
|
38 |
with gr.Blocks(theme="soft") as demo:
|
39 |
-
gr.Markdown("#
|
40 |
|
41 |
-
# Symptom
|
42 |
with gr.Row():
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
diagnose_button.click(diagnose, inputs=symptoms_input, outputs=symptoms_output)
|
47 |
|
48 |
-
# Gut
|
49 |
with gr.Row():
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
gut_button.click(gut_health_analysis, inputs=diet_input, outputs=gut_output)
|
54 |
|
55 |
# Retina scan
|
56 |
with gr.Row():
|
57 |
retina_input = gr.Image(label="Upload Retina Image")
|
58 |
-
retina_output = gr.Textbox(label="Retina
|
59 |
-
|
60 |
-
retina_button.click(retina_scan, inputs=retina_input, outputs=retina_output)
|
61 |
|
62 |
-
#
|
63 |
with gr.Row():
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
chat_button.click(chatbot, inputs=chat_input, outputs=chat_output)
|
68 |
|
69 |
-
gr.Markdown("π **Diagnosify-AI** - AI-powered
|
70 |
|
71 |
-
#
|
72 |
demo.launch()
|
73 |
|
74 |
|
|
|
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 AI models
|
10 |
+
symptom_model = pipeline("text-classification", model="nlp-ai/symptom-disease") # Replace with trained model
|
11 |
+
emotion_model = pipeline("sentiment-analysis") # Pre-trained NLP for emotions
|
12 |
+
retina_model = tf.keras.models.load_model("retina_disease_model.h5") # Custom trained Retina AI
|
13 |
+
stool_model = tf.keras.models.load_model("stool_microbiome_model.h5") # Gut microbiome detection AI
|
14 |
+
|
15 |
+
# Function for AI-powered diagnosis
|
16 |
def diagnose(symptoms):
|
17 |
+
result = symptom_model(symptoms)[0]
|
18 |
+
return f"Condition: {result['label']} (Confidence: {round(result['score'] * 100, 2)}%)"
|
19 |
+
|
20 |
+
# Function for stool image microbiome analysis
|
21 |
+
def analyze_stool(image):
|
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 |
+
img = Image.open(image).resize((224, 224))
|
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(theme="soft") as demo:
|
52 |
+
gr.Markdown("# π₯ Diagnosify-AI: AI-powered Health & Disease Detection")
|
53 |
|
54 |
+
# Symptom diagnosis
|
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 |
# Retina scan
|
67 |
with gr.Row():
|
68 |
retina_input = gr.Image(label="Upload Retina Image")
|
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 |
+
# Emotion-to-Disease
|
73 |
with gr.Row():
|
74 |
+
emotion_input = gr.Textbox(label="Describe your emotions")
|
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 |
+
gr.Markdown("π **Diagnosify-AI** - Bringing AI-powered diagnostics to your fingertips!")
|
79 |
|
80 |
+
# Launch the app
|
81 |
demo.launch()
|
82 |
|
83 |
|