Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,9 @@ from transformers import pipeline
|
|
4 |
# Function for image classification
|
5 |
def classify(image, model_name):
|
6 |
try:
|
|
|
7 |
pipe = pipeline("image-classification", model=model_name)
|
|
|
8 |
results = pipe(image)
|
9 |
return {result["label"]: round(result["score"], 2) for result in results}
|
10 |
except Exception as e:
|
@@ -21,6 +23,10 @@ demo = gr.Interface(
|
|
21 |
outputs=gr.Label(num_top_classes=3, label="Top Predictions"),
|
22 |
title="Custom timm Model Image Classifier",
|
23 |
description="Enter a timm model name from Hugging Face, upload an image, and get predictions.",
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
demo.launch()
|
|
|
4 |
# Function for image classification
|
5 |
def classify(image, model_name):
|
6 |
try:
|
7 |
+
# Load the pipeline with the given model name
|
8 |
pipe = pipeline("image-classification", model=model_name)
|
9 |
+
# Perform image classification
|
10 |
results = pipe(image)
|
11 |
return {result["label"]: round(result["score"], 2) for result in results}
|
12 |
except Exception as e:
|
|
|
23 |
outputs=gr.Label(num_top_classes=3, label="Top Predictions"),
|
24 |
title="Custom timm Model Image Classifier",
|
25 |
description="Enter a timm model name from Hugging Face, upload an image, and get predictions.",
|
26 |
+
examples=[
|
27 |
+
["cat.png", "timm/mobilenetv3_small_100.lamb_in1k"],
|
28 |
+
["cat.png", "timm/resnet50.a1_in1k"],
|
29 |
+
],
|
30 |
)
|
31 |
|
32 |
demo.launch()
|