M3ash commited on
Commit
363a7c7
Β·
verified Β·
1 Parent(s): 4959159

Rename app_py.py to app.py

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. app_py.py +0 -60
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ import json
4
+ import gradio as gr
5
+ from PIL import Image
6
+
7
+ # Load model
8
+ model = tf.keras.models.load_model("food_vision_model.keras")
9
+
10
+ # Load metadata
11
+ with open("dermnet_disease_info.json", "r") as f:
12
+ disease_info = json.load(f)
13
+
14
+ class_names = list(disease_info.keys())
15
+
16
+ def load_and_prep_image(img, img_size=(224, 224)):
17
+ img = img.resize(img_size)
18
+ img_array = tf.keras.preprocessing.image.img_to_array(img)
19
+ img_array = tf.expand_dims(img_array, axis=0)
20
+ img_array = tf.keras.applications.efficientnet.preprocess_input(img_array)
21
+ return img_array
22
+
23
+ def predict(img):
24
+ img_array = load_and_prep_image(img)
25
+ pred = model.predict(img_array)[0]
26
+ pred_class = class_names[np.argmax(pred)]
27
+ confidence = float(np.max(pred))
28
+ info = disease_info.get(pred_class, {})
29
+
30
+ result = f"🧬 **Disease Prediction:** {pred_class} ({confidence:.2%})\n\n"
31
+ result += f"πŸ“– **Description:** {info['description']}\n\n"
32
+ result += f"🩺 **Symptoms:** {', '.join(info['symptoms'])}\n\n"
33
+ result += f"πŸ§ͺ **Causes:** {', '.join(info['causes'])}\n\n"
34
+ result += f"πŸ’Š **Treatments:** {', '.join(info['treatments'])}\n\n"
35
+ result += f"πŸ§β€β™‚οΈ **Contagious:** {'Yes' if info['is_contagious'] else 'No'}"
36
+
37
+ return result
38
+
39
+ # Gradio interface
40
+ demo = gr.Interface(
41
+ fn=predict_disease,
42
+ inputs=gr.Image(type="pil"),
43
+ outputs="markdown",
44
+ title="πŸ§ͺ Skin Disease Classifier",
45
+ description="Upload a skin image to classify and learn about the predicted skin condition.",
46
+ examples=None
47
+ )
48
+ demo.launch(debug=True)
app_py.py DELETED
@@ -1,60 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """app.py
3
-
4
- Automatically generated by Colab.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1izoc0P_UOwPr0z8UQvbf4s88qxqA-QTK
8
- """
9
-
10
- from google.colab import drive
11
- drive.mount('/content/drive')
12
-
13
- from tensorflow.keras.models import load_model
14
-
15
- model = load_model('/content/drive/MyDrive/skin_disease_model.h5')
16
-
17
- import gradio as gr
18
- import tensorflow as tf
19
- import numpy as np
20
- from PIL import Image
21
-
22
- # Load model
23
- model = tf.keras.models.load_model('/content/drive/MyDrive/skin_disease_model.h5') # or .keras
24
-
25
- # Define your class names
26
- class_names = ['Acne', 'Eczema', 'Fungal Infection', 'Psoriasis', 'Rosacea'] # replace with your actual classes
27
-
28
- # Preprocessing function
29
- def preprocess_image(image):
30
- image = image.resize((180, 180))
31
- image = np.array(image) / 255.0
32
- image = np.expand_dims(image, axis=0)
33
- return image
34
-
35
- # Prediction function
36
- def predict_skin_disease(img):
37
- processed = preprocess_image(img)
38
- pred = model.predict(processed)[0]
39
- top_class = np.argmax(pred)
40
- confidence = float(pred[top_class])
41
- return {class_names[i]: float(pred[i]) for i in range(len(class_names))}
42
-
43
- # Gradio Interface
44
- interface = gr.Interface(
45
- fn=predict_skin_disease,
46
- inputs=gr.Image(type="pil"),
47
- outputs=gr.Label(num_top_classes=3),
48
- title="Skin Disease Classifier",
49
- description="Upload a skin image to get a disease prediction."
50
- )
51
-
52
- interface.launch()
53
-
54
- import gradio as gr
55
-
56
- def classify(img):
57
- return "Result"
58
-
59
- demo = gr.Interface(fn=classify, inputs="image", outputs="text")
60
- demo.launch() # βœ… REQUIRED