Spaces:
Build error
Build error
ahmeds26
commited on
Commit
·
62106e2
1
Parent(s):
d5e7906
Add application files
Browse files- app.py +45 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
global pipeline
|
| 5 |
+
global default_model_name
|
| 6 |
+
default_model_name = "google/vit-base-patch16-224"
|
| 7 |
+
|
| 8 |
+
def predict(image, model_name):
|
| 9 |
+
pipe = pipeline(task="image-classification", model=model_name)
|
| 10 |
+
predictions = pipe(image)
|
| 11 |
+
return {p["label"]: p["score"] for p in predictions}
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
gr.Markdown(
|
| 18 |
+
"""
|
| 19 |
+
# Settings
|
| 20 |
+
[Here](https://huggingface.co/models?pipeline_tag=image-classification&sort=downloads) are some popular image classification models.
|
| 21 |
+
Or use default model **"google/vit-base-patch16-224"**
|
| 22 |
+
""")
|
| 23 |
+
gr.Markdown(
|
| 24 |
+
"""
|
| 25 |
+
# Image Classifier Result
|
| 26 |
+
""")
|
| 27 |
+
with gr.Row():
|
| 28 |
+
with gr.Column(scale=1):
|
| 29 |
+
input_model = gr.Textbox(label="Enter a custom model name:", value=default_model_name, scale=1)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
gr.Markdown("Upload image")
|
| 33 |
+
#images_input = gr.File(file_count="multiple", file_types=["image"], label="Input images", scale=1)
|
| 34 |
+
#images_input = gr.Files(file_count="multiple", file_types=["image"], label="Input images", scale=1)
|
| 35 |
+
input_image = gr.Image(label="Input Image", type="filepath")
|
| 36 |
+
|
| 37 |
+
#output = gr.Label(label="Output", num_top_classes=3, scale=2)
|
| 38 |
+
output = gr.Label(num_top_classes=10, scale=2)
|
| 39 |
+
with gr.Row(equal_height=True):
|
| 40 |
+
clear_button = gr.ClearButton(value="Clear", scale=0)
|
| 41 |
+
submit_button = gr.Button(value="Submit", variant="primary", scale=0)
|
| 42 |
+
submit_button.click(fn=predict, inputs=[input_image, input_model], outputs=output)
|
| 43 |
+
clear_button.click(lambda: [None, None, None], outputs=[input_model, input_image, output])
|
| 44 |
+
|
| 45 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.44.4
|
| 2 |
+
transformers==4.33.2
|