Spaces:
Running
Running
import gradio as gr | |
import torch | |
from transformers import pipeline | |
import tensorflow as tf | |
import numpy as np | |
from PIL import Image | |
import random | |
# Load AI models | |
symptom_model = pipeline("text-classification", model="nlp-ai/symptom-disease") # Replace with trained model | |
emotion_model = pipeline("sentiment-analysis") # Pre-trained NLP for emotions | |
retina_model = tf.keras.models.load_model("retina_disease_model.h5") # Custom trained Retina AI | |
stool_model = tf.keras.models.load_model("stool_microbiome_model.h5") # Gut microbiome detection AI | |
# Function for AI-powered diagnosis | |
def diagnose(symptoms): | |
result = symptom_model(symptoms)[0] | |
return f"Condition: {result['label']} (Confidence: {round(result['score'] * 100, 2)}%)" | |
# Function for stool image microbiome analysis | |
def analyze_stool(image): | |
img = Image.open(image).resize((224, 224)) | |
img_array = np.array(img) / 255.0 | |
img_array = np.expand_dims(img_array, axis=0) | |
prediction = stool_model.predict(img_array) | |
class_names = ["Healthy Gut", "Possible Dysbiosis", "Severe Gut Imbalance"] | |
return f"Result: {class_names[np.argmax(prediction)]}" | |
# Retina disease detection function | |
def analyze_retina(image): | |
img = Image.open(image).resize((224, 224)) | |
img_array = np.array(img) / 255.0 | |
img_array = np.expand_dims(img_array, axis=0) | |
prediction = retina_model.predict(img_array) | |
class_names = ["Normal Retina", "Diabetic Retinopathy", "Glaucoma Detected"] | |
return f"Retina Scan: {class_names[np.argmax(prediction)]}" | |
# Emotion-to-disease analysis | |
def emotion_to_disease(emotion_text): | |
emotions = { | |
"stress": "Long-term stress can cause high blood pressure, anxiety, and digestive issues.", | |
"anger": "Frequent anger can increase heart disease risk.", | |
"happiness": "A positive mindset improves overall well-being!" | |
} | |
detected_emotion = emotion_model(emotion_text)[0]['label'] | |
return emotions.get(detected_emotion.lower(), "No specific health risks detected.") | |
# Gradio UI | |
with gr.Blocks(theme="soft") as demo: | |
gr.Markdown("# π₯ Diagnosify-AI: AI-powered Health & Disease Detection") | |
# Symptom diagnosis | |
with gr.Row(): | |
symptom_input = gr.Textbox(label="Enter symptoms") | |
symptom_output = gr.Textbox(label="Diagnosis Result", interactive=False) | |
gr.Button("Diagnose").click(diagnose, inputs=symptom_input, outputs=symptom_output) | |
# Gut microbiome (stool analysis) | |
with gr.Row(): | |
stool_input = gr.Image(label="Upload Stool Image") | |
stool_output = gr.Textbox(label="Microbiome Analysis", interactive=False) | |
gr.Button("Analyze Stool").click(analyze_stool, inputs=stool_input, outputs=stool_output) | |
# Retina scan | |
with gr.Row(): | |
retina_input = gr.Image(label="Upload Retina Image") | |
retina_output = gr.Textbox(label="Retina Disease Detection", interactive=False) | |
gr.Button("Analyze Retina").click(analyze_retina, inputs=retina_input, outputs=retina_output) | |
# Emotion-to-Disease | |
with gr.Row(): | |
emotion_input = gr.Textbox(label="Describe your emotions") | |
emotion_output = gr.Textbox(label="Health Analysis", interactive=False) | |
gr.Button("Analyze Emotion").click(emotion_to_disease, inputs=emotion_input, outputs=emotion_output) | |
gr.Markdown("π **Diagnosify-AI** - Bringing AI-powered diagnostics to your fingertips!") | |
# Launch the app | |
demo.launch() | |