Spaces:
Sleeping
Sleeping
Commit
·
3e7dbba
1
Parent(s):
a611015
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import gdown
|
4 |
-
|
5 |
-
from PIL import Image, ImageDraw
|
6 |
|
7 |
input_shape = (32, 32, 3)
|
8 |
resized_shape = (224, 224, 3)
|
@@ -42,34 +41,15 @@ def predict_class(image):
|
|
42 |
predicted_class = labels[class_index]
|
43 |
return predicted_class
|
44 |
|
45 |
-
# Perform object detection
|
46 |
-
def detect_objects(image):
|
47 |
-
img = image.copy()
|
48 |
-
img = tf.image.resize(img, [input_shape[0], input_shape[1]])
|
49 |
-
img = tf.expand_dims(img, axis=0)
|
50 |
-
prediction = model.predict(img)
|
51 |
-
boxes, scores, classes = prediction[0]['detection_boxes'], prediction[0]['detection_scores'], prediction[0]['detection_classes']
|
52 |
-
height, width, _ = img.shape
|
53 |
-
draw = ImageDraw.Draw(image)
|
54 |
-
for box, score, _class in zip(boxes, scores, classes):
|
55 |
-
if score > 0.5:
|
56 |
-
ymin, xmin, ymax, xmax = box
|
57 |
-
left, right, top, bottom = xmin * width, xmax * width, ymin * height, ymax * height
|
58 |
-
draw.rectangle([(left, top), (right, bottom)], outline='red', width=2)
|
59 |
-
draw.text((left, top - 10), labels[int(_class)], fill='red')
|
60 |
-
|
61 |
-
return image
|
62 |
-
|
63 |
# UI Design
|
64 |
def classify_image(image):
|
65 |
predicted_class = predict_class(image)
|
66 |
-
|
67 |
-
return image_with_box, predicted_class
|
68 |
|
69 |
inputs = gr.inputs.Image(label="Upload an image")
|
70 |
-
outputs = gr.outputs.
|
71 |
|
72 |
-
title = "Image Classifier
|
73 |
-
description = "Upload an image and get the predicted class
|
74 |
|
75 |
gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title=title, description=description).launch(inline=True)
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import gdown
|
4 |
+
from PIL import Image
|
|
|
5 |
|
6 |
input_shape = (32, 32, 3)
|
7 |
resized_shape = (224, 224, 3)
|
|
|
41 |
predicted_class = labels[class_index]
|
42 |
return predicted_class
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# UI Design
|
45 |
def classify_image(image):
|
46 |
predicted_class = predict_class(image)
|
47 |
+
return predicted_class
|
|
|
48 |
|
49 |
inputs = gr.inputs.Image(label="Upload an image")
|
50 |
+
outputs = gr.outputs.Textbox(label="Predicted Class", live=True)
|
51 |
|
52 |
+
title = "Image Classifier"
|
53 |
+
description = "Upload an image and get the predicted class."
|
54 |
|
55 |
gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title=title, description=description).launch(inline=True)
|