Nadera03 commited on
Commit
74caea8
Β·
verified Β·
1 Parent(s): c417f09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -48
app.py CHANGED
@@ -1,74 +1,83 @@
1
  import gradio as gr
 
 
 
 
 
2
  import random
3
 
4
- # Symptom-based diagnosis function
 
 
 
 
 
 
5
  def diagnose(symptoms):
6
- symptom_disease_mapping = {
7
- "fever, cold, flu": "Possible conditions: Common Cold, Influenza.",
8
- "cough, fever, difficulty breathing": "Possible conditions: COVID-19, Pneumonia.",
9
- "headache, nausea, dizziness": "Possible conditions: Migraine, Dehydration.",
10
- "stomach pain, nausea, vomiting": "Possible conditions: Food Poisoning, Gastritis."
11
- }
 
 
12
 
13
- return symptom_disease_mapping.get(symptoms.lower(), "Not enough data, please consult a doctor.")
 
 
14
 
15
- # Gut health analysis function
16
- def gut_health_analysis(diet):
17
- if "junk" in diet.lower():
18
- return "Unhealthy gut! Try probiotic-rich foods like yogurt, kimchi, or kefir."
19
- elif "fruits" in diet.lower() or "vegetables" in diet.lower():
20
- return "Healthy gut! Your microbiome is balanced."
21
- else:
22
- return "Gut health status unclear. Maintain a fiber-rich diet."
23
 
24
- # Retina scan function (Mock output)
25
- def retina_scan(image):
26
- return f"Retina scan result: No abnormalities detected. (For real diagnosis, consult a specialist)"
27
 
28
- # Simple chatbot function
29
- def chatbot(query):
30
- responses = {
31
- "hello": "Hello! How can I assist you?",
32
- "what is ai": "AI (Artificial Intelligence) is the simulation of human intelligence by machines.",
33
- "how to stay healthy": "Eat balanced meals, exercise daily, stay hydrated, and get enough sleep."
34
  }
35
- return responses.get(query.lower(), "I'm not sure about that. Please consult a doctor.")
 
36
 
37
- # Creating Gradio UI
38
  with gr.Blocks(theme="soft") as demo:
39
- gr.Markdown("# πŸ”¬ Diagnosify-AI: Your AI-powered Health Assistant")
40
 
41
- # Symptom-based diagnosis
42
  with gr.Row():
43
- symptoms_input = gr.Textbox(label="Enter symptoms (comma separated)")
44
- symptoms_output = gr.Textbox(label="Diagnosis Result", interactive=False)
45
- diagnose_button = gr.Button("Diagnose")
46
- diagnose_button.click(diagnose, inputs=symptoms_input, outputs=symptoms_output)
47
 
48
- # Gut health analysis
49
  with gr.Row():
50
- diet_input = gr.Textbox(label="Describe your diet")
51
- gut_output = gr.Textbox(label="Gut Health Status", interactive=False)
52
- gut_button = gr.Button("Analyze Gut Health")
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 Scan Report", interactive=False)
59
- retina_button = gr.Button("Analyze Retina Scan")
60
- retina_button.click(retina_scan, inputs=retina_input, outputs=retina_output)
61
 
62
- # Simple chatbot
63
  with gr.Row():
64
- chat_input = gr.Textbox(label="Ask me anything")
65
- chat_output = gr.Textbox(label="Bot Response", interactive=False)
66
- chat_button = gr.Button("Ask")
67
- chat_button.click(chatbot, inputs=chat_input, outputs=chat_output)
68
 
69
- gr.Markdown("πŸ”— **Diagnosify-AI** - AI-powered medical insights at your fingertips!")
70
 
71
- # Launching the app
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