Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# ViT-Modell
|
| 5 |
-
vit_classifier = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# SIGLIP
|
| 8 |
siglip_detector = pipeline(
|
| 9 |
model="google/siglip-so400m-patch14-384",
|
| 10 |
-
task="zero-shot-image-classification"
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
labels_oxford_pets = [
|
|
@@ -20,13 +27,13 @@ labels_oxford_pets = [
|
|
| 20 |
|
| 21 |
def classify_pet(image):
|
| 22 |
vit_results = vit_classifier(image)
|
| 23 |
-
vit_output = {
|
| 24 |
|
| 25 |
siglip_results = siglip_detector(image, candidate_labels=labels_oxford_pets)
|
| 26 |
-
siglip_output = {
|
| 27 |
|
| 28 |
return {
|
| 29 |
-
"ViT Classification": vit_output,
|
| 30 |
"SIGLIP Zero-Shot Classification": siglip_output
|
| 31 |
}
|
| 32 |
|
|
@@ -43,7 +50,7 @@ iface = gr.Interface(
|
|
| 43 |
inputs=gr.Image(type="filepath"),
|
| 44 |
outputs=gr.JSON(),
|
| 45 |
title="Pet Classification Comparison",
|
| 46 |
-
description="
|
| 47 |
examples=example_images
|
| 48 |
)
|
| 49 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# ViT-Modell (dein trainiertes Modell von Hugging Face)
|
| 5 |
+
vit_classifier = pipeline(
|
| 6 |
+
"image-classification",
|
| 7 |
+
model="dewiri/vit-base-oxford-iiit-pets",
|
| 8 |
+
top_k=3,
|
| 9 |
+
device=0 # GPU, falls verfügbar
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
# SIGLIP für Zero-Shot Klassifikation
|
| 13 |
siglip_detector = pipeline(
|
| 14 |
model="google/siglip-so400m-patch14-384",
|
| 15 |
+
task="zero-shot-image-classification",
|
| 16 |
+
top_k=3,
|
| 17 |
+
device=0
|
| 18 |
)
|
| 19 |
|
| 20 |
labels_oxford_pets = [
|
|
|
|
| 27 |
|
| 28 |
def classify_pet(image):
|
| 29 |
vit_results = vit_classifier(image)
|
| 30 |
+
vit_output = {res['label']: round(res['score'], 3) for res in vit_results}
|
| 31 |
|
| 32 |
siglip_results = siglip_detector(image, candidate_labels=labels_oxford_pets)
|
| 33 |
+
siglip_output = {res['label']: round(res['score'], 3) for res in siglip_results}
|
| 34 |
|
| 35 |
return {
|
| 36 |
+
"ViT Classification (dewiri)": vit_output,
|
| 37 |
"SIGLIP Zero-Shot Classification": siglip_output
|
| 38 |
}
|
| 39 |
|
|
|
|
| 50 |
inputs=gr.Image(type="filepath"),
|
| 51 |
outputs=gr.JSON(),
|
| 52 |
title="Pet Classification Comparison",
|
| 53 |
+
description="Compare a fine-tuned ViT model (dewiri/vit-base-oxford-iiit-pets) with a SIGLIP zero-shot classifier.",
|
| 54 |
examples=example_images
|
| 55 |
)
|
| 56 |
|