Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
5 |
-
import requests
|
6 |
|
7 |
model_names = [
|
8 |
"0-ma/swin-geometric-shapes-tiny",
|
@@ -47,23 +46,27 @@ def predict(image, selected_model):
|
|
47 |
return confidences
|
48 |
|
49 |
title = "Geometric Shape Classifier"
|
50 |
-
description = "Select a model to classify geometric shapes."
|
51 |
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
iface = gr.Interface(
|
57 |
-
fn=predict,
|
58 |
-
inputs=[
|
59 |
-
gr.Image(type="pil"),
|
60 |
-
gr.Dropdown(choices=model_names, label="Select Model", value=model_names[0])
|
61 |
-
],
|
62 |
-
outputs=gr.Label(),
|
63 |
-
title=title,
|
64 |
-
description=description,
|
65 |
-
examples=examples
|
66 |
-
)
|
67 |
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
|
|
5 |
|
6 |
model_names = [
|
7 |
"0-ma/swin-geometric-shapes-tiny",
|
|
|
46 |
return confidences
|
47 |
|
48 |
title = "Geometric Shape Classifier"
|
49 |
+
description = "Select a model and upload an image to classify geometric shapes."
|
50 |
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown(f"# {title}")
|
53 |
+
gr.Markdown(description)
|
54 |
+
|
55 |
+
with gr.Row():
|
56 |
+
model_dropdown = gr.Dropdown(choices=model_names, label="Select Model", value=model_names[0])
|
57 |
+
image_input = gr.Image(type="pil")
|
58 |
+
|
59 |
+
submit_button = gr.Button("Classify")
|
60 |
+
output = gr.Label()
|
61 |
|
62 |
+
submit_button.click(fn=predict, inputs=[image_input, model_dropdown], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
gr.Examples(
|
65 |
+
examples=[[img, model_names[0]] for img in example_images],
|
66 |
+
inputs=[image_input, model_dropdown],
|
67 |
+
outputs=output,
|
68 |
+
fn=predict,
|
69 |
+
cache_examples=True,
|
70 |
+
)
|
71 |
+
|
72 |
+
demo.launch()
|