Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,12 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from torchvision import transforms
|
4 |
from PIL import Image
|
5 |
-
import os
|
6 |
|
7 |
# Define the lesion type mapping
|
8 |
lesion_type_dict = {
|
9 |
0: 'Actinic keratoses',
|
10 |
1: 'Basal cell carcinoma',
|
11 |
-
2: 'Benign keratosis-like lesions',
|
12 |
3: 'Dermatofibroma',
|
13 |
4: 'Melanocytic nevi',
|
14 |
5: 'Melanoma',
|
@@ -24,6 +23,7 @@ model = load_model() # Load the model onto CPU
|
|
24 |
|
25 |
# Function to preprocess the image and predict the class
|
26 |
def classify_img(img):
|
|
|
27 |
preprocess = transforms.Compose([
|
28 |
transforms.Resize((224, 224)), # Adjust as needed
|
29 |
transforms.ToTensor(),
|
@@ -55,25 +55,25 @@ def classify_img(img):
|
|
55 |
|
56 |
return output_text # Return formatted text as a single string
|
57 |
|
|
|
|
|
|
|
58 |
|
59 |
-
#
|
60 |
-
example_images = [
|
61 |
-
["examples/Actinic keratoses.jpg", "Actinic keratoses"], # First image and its label
|
62 |
-
["examples/Basal cell carcinoma.jpg", "Basal cell carcinoma"], # Second image and its label
|
63 |
-
["examples/Benign keratosis-like lesions.jpg", "Benign keratosis-like lesions"], # And so on
|
64 |
-
["examples/Dermatofibroma.jpg", "Dermatofibroma"],
|
65 |
-
["examples/melanoma.jpg", "Melanoma"],
|
66 |
-
["examples/Melanocytic nevi.jpg", "Melanocytic nevi"],
|
67 |
-
["examples/Vascular lesions.jpg", "Vascular lesions"],
|
68 |
-
]
|
69 |
-
|
70 |
-
# Set up Gradio interface with examples as a list of tuples
|
71 |
iface = gr.Interface(
|
72 |
fn=classify_img, # Prediction function
|
73 |
-
inputs=
|
74 |
-
outputs=
|
75 |
-
examples=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
)
|
77 |
|
78 |
# Launch the Gradio interface
|
79 |
-
iface.launch() # Start the Gradio
|
|
|
2 |
import torch
|
3 |
from torchvision import transforms
|
4 |
from PIL import Image
|
|
|
5 |
|
6 |
# Define the lesion type mapping
|
7 |
lesion_type_dict = {
|
8 |
0: 'Actinic keratoses',
|
9 |
1: 'Basal cell carcinoma',
|
10 |
+
2: 'Benign keratosis-like lesions ',
|
11 |
3: 'Dermatofibroma',
|
12 |
4: 'Melanocytic nevi',
|
13 |
5: 'Melanoma',
|
|
|
23 |
|
24 |
# Function to preprocess the image and predict the class
|
25 |
def classify_img(img):
|
26 |
+
# Preprocess the image
|
27 |
preprocess = transforms.Compose([
|
28 |
transforms.Resize((224, 224)), # Adjust as needed
|
29 |
transforms.ToTensor(),
|
|
|
55 |
|
56 |
return output_text # Return formatted text as a single string
|
57 |
|
58 |
+
# Gradio interface setup
|
59 |
+
image = gr.Image() # Input is an image
|
60 |
+
label = gr.Textbox() # Output as formatted text
|
61 |
|
62 |
+
# Set up Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
iface = gr.Interface(
|
64 |
fn=classify_img, # Prediction function
|
65 |
+
inputs=image, # Image input
|
66 |
+
outputs=label, # Output as formatted text
|
67 |
+
examples=[
|
68 |
+
["examples/Actinic keratoses.jpg", "Actinic keratoses"], # First image and its label
|
69 |
+
["examples/Basal cell carcinoma.jpg", "Basal cell carcinoma"], # Second image and its label
|
70 |
+
["examples/Benign keratosis-like lesions.jpg", "Benign keratosis-like lesions"], # And so on
|
71 |
+
["examples/Dermatofibroma.jpg", "Dermatofibroma"],
|
72 |
+
["examples/melanoma.jpg", "Melanoma"],
|
73 |
+
["examples/Melanocytic nevi.jpg", "Melanocytic nevi"],
|
74 |
+
["examples/Vascular lesions.jpg", "Vascular lesions"],
|
75 |
+
]
|
76 |
)
|
77 |
|
78 |
# Launch the Gradio interface
|
79 |
+
iface.launch() # Start the local Gradio server
|