dewiri commited on
Commit
ab3cb42
·
verified ·
1 Parent(s): 128690f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -1,13 +1,20 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # ViT-Modell für klassische Klassifikation
5
- vit_classifier = pipeline("image-classification", model="dewiri/vit-base-oxford-iiit-pets")
 
 
 
 
 
6
 
7
- # SIGLIP-Modell für Zero-Shot Klassifikation (anstelle von CLIP)
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 = {result['label']: result['score'] for result in vit_results}
24
 
25
  siglip_results = siglip_detector(image, candidate_labels=labels_oxford_pets)
26
- siglip_output = {result['label']: result['score'] for result in siglip_results}
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="Upload an image of a pet, and compare results from a trained ViT model and a zero-shot SIGLIP model.",
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