Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -255,10 +255,8 @@ def predict(image):
|
|
255 |
# Normalize the image
|
256 |
mean = [0.485, 0.456, 0.406]
|
257 |
std = [0.229, 0.224, 0.225]
|
258 |
-
|
259 |
mean = np.expand_dims(mean, axis=(1,2))
|
260 |
std = np.expand_dims(std, axis=(1,2))
|
261 |
-
|
262 |
image = (image / 255.0 - mean)/std
|
263 |
|
264 |
# Convert the image to a numpy array and add a batch dimension
|
@@ -268,7 +266,6 @@ def predict(image):
|
|
268 |
|
269 |
# Make prediction
|
270 |
output = model.run(None, {input_name: image})
|
271 |
-
|
272 |
|
273 |
print("type output:", type(output))
|
274 |
print(output)
|
@@ -281,13 +278,17 @@ def predict(image):
|
|
281 |
print("type annotated image:", type(annotated_img))
|
282 |
print(annotated_img)
|
283 |
|
|
|
|
|
|
|
284 |
return annotated_img
|
285 |
|
286 |
# Gradio interface
|
287 |
demo = gr.Interface(
|
288 |
fn=predict,
|
289 |
inputs=gr.Image(sources=["webcam"], type="numpy"), # Accepts image input
|
290 |
-
outputs="annotatedimage" # Customize based on your output format
|
|
|
291 |
)
|
292 |
|
293 |
if __name__ == "__main__":
|
|
|
255 |
# Normalize the image
|
256 |
mean = [0.485, 0.456, 0.406]
|
257 |
std = [0.229, 0.224, 0.225]
|
|
|
258 |
mean = np.expand_dims(mean, axis=(1,2))
|
259 |
std = np.expand_dims(std, axis=(1,2))
|
|
|
260 |
image = (image / 255.0 - mean)/std
|
261 |
|
262 |
# Convert the image to a numpy array and add a batch dimension
|
|
|
266 |
|
267 |
# Make prediction
|
268 |
output = model.run(None, {input_name: image})
|
|
|
269 |
|
270 |
print("type output:", type(output))
|
271 |
print(output)
|
|
|
278 |
print("type annotated image:", type(annotated_img))
|
279 |
print(annotated_img)
|
280 |
|
281 |
+
# Convert to PIL Image
|
282 |
+
annotated_img = Image.fromarray(annotated_img)
|
283 |
+
|
284 |
return annotated_img
|
285 |
|
286 |
# Gradio interface
|
287 |
demo = gr.Interface(
|
288 |
fn=predict,
|
289 |
inputs=gr.Image(sources=["webcam"], type="numpy"), # Accepts image input
|
290 |
+
# outputs="annotatedimage" # Customize based on your output format
|
291 |
+
outputs=gr.Image(type="pil"), # Accepts image input
|
292 |
)
|
293 |
|
294 |
if __name__ == "__main__":
|