Spaces:
Sleeping
Sleeping
Commit
·
6bae92b
1
Parent(s):
7442cbf
blank page
Browse files
app.py
CHANGED
|
@@ -5,39 +5,39 @@ from PIL import Image
|
|
| 5 |
import requests
|
| 6 |
|
| 7 |
# Load the pre-trained ResNet model
|
| 8 |
-
model = models.mobilenet_v2(pretrained=True)
|
| 9 |
-
model.eval()
|
| 10 |
|
| 11 |
-
# Define the transformation for input images
|
| 12 |
-
preprocess = transforms.Compose([
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
])
|
| 18 |
|
| 19 |
-
# Define the labels for ImageNet classes (you may need to adjust this based on your model)
|
| 20 |
-
LABELS_URL = "https://raw.githubusercontent.com/anishathalye/imagenet-simple-labels/master/imagenet-simple-labels.json"
|
| 21 |
-
response = requests.get(LABELS_URL)
|
| 22 |
-
labels = response.text.splitlines()
|
| 23 |
|
| 24 |
-
# Function to perform image classification
|
| 25 |
-
def classify_image(input_image):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
# Gradio UI components
|
| 43 |
image_input = gr.Image()
|
|
@@ -45,7 +45,7 @@ output_label = gr.Textbox()
|
|
| 45 |
|
| 46 |
# Gradio interface
|
| 47 |
iface = gr.Interface(
|
| 48 |
-
fn=
|
| 49 |
inputs=image_input,
|
| 50 |
outputs=output_label,
|
| 51 |
live=True,
|
|
|
|
| 5 |
import requests
|
| 6 |
|
| 7 |
# Load the pre-trained ResNet model
|
| 8 |
+
# model = models.mobilenet_v2(pretrained=True)
|
| 9 |
+
# model.eval()
|
| 10 |
|
| 11 |
+
# # Define the transformation for input images
|
| 12 |
+
# preprocess = transforms.Compose([
|
| 13 |
+
# transforms.Resize(256),
|
| 14 |
+
# transforms.CenterCrop(224),
|
| 15 |
+
# transforms.ToTensor(),
|
| 16 |
+
# transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 17 |
+
# ])
|
| 18 |
|
| 19 |
+
# # Define the labels for ImageNet classes (you may need to adjust this based on your model)
|
| 20 |
+
# LABELS_URL = "https://raw.githubusercontent.com/anishathalye/imagenet-simple-labels/master/imagenet-simple-labels.json"
|
| 21 |
+
# response = requests.get(LABELS_URL)
|
| 22 |
+
# labels = response.text.splitlines()
|
| 23 |
|
| 24 |
+
# # Function to perform image classification
|
| 25 |
+
# def classify_image(input_image):
|
| 26 |
+
# # Preprocess the image
|
| 27 |
+
# input_tensor = preprocess(input_image)
|
| 28 |
+
# input_batch = input_tensor.unsqueeze(0)
|
| 29 |
|
| 30 |
+
# # Make predictions
|
| 31 |
+
# with torch.no_grad():
|
| 32 |
+
# output = model(input_batch)
|
| 33 |
|
| 34 |
+
# # Get the predicted class index
|
| 35 |
+
# _, predicted_idx = torch.max(output, 1)
|
| 36 |
|
| 37 |
+
# # Get the predicted label
|
| 38 |
+
# predicted_label = labels[predicted_idx.item()]
|
| 39 |
|
| 40 |
+
# return predicted_label
|
| 41 |
|
| 42 |
# Gradio UI components
|
| 43 |
image_input = gr.Image()
|
|
|
|
| 45 |
|
| 46 |
# Gradio interface
|
| 47 |
iface = gr.Interface(
|
| 48 |
+
fn=None,
|
| 49 |
inputs=image_input,
|
| 50 |
outputs=output_label,
|
| 51 |
live=True,
|