Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- .gitattributes +5 -0
- app.py +48 -0
- example_images/000002.png +3 -0
- example_images/000011.jpg +3 -0
- example_images/000048.png +3 -0
- example_images/Chihiro_13.PNG +3 -0
- example_images/Kiki_01.PNG +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
example_images/000002.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
example_images/000011.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
example_images/000048.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
example_images/Chihiro_13.PNG filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
example_images/Kiki_01.PNG filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load your fine-tuned ViT model
|
| 5 |
+
vit_classifier = pipeline("image-classification", model="itsJasminZWIN/chihiro-classifier")
|
| 6 |
+
|
| 7 |
+
# Load CLIP zero-shot model
|
| 8 |
+
clip_detector = pipeline(model="openai/clip-vit-base-patch32", task="zero-shot-image-classification")
|
| 9 |
+
|
| 10 |
+
# Labels for both models
|
| 11 |
+
label_names = ['chihiro', 'not chihiro']
|
| 12 |
+
|
| 13 |
+
# Define classification function
|
| 14 |
+
def classify_character(image):
|
| 15 |
+
# Run ViT classifier
|
| 16 |
+
vit_results = vit_classifier(image)
|
| 17 |
+
vit_output = {res['label']: round(res['score'], 4) for res in vit_results}
|
| 18 |
+
|
| 19 |
+
# Run CLIP zero-shot classifier
|
| 20 |
+
clip_results = clip_detector(image, candidate_labels=label_names)
|
| 21 |
+
clip_output = {res['label']: round(res['score'], 4) for res in clip_results}
|
| 22 |
+
|
| 23 |
+
return {
|
| 24 |
+
"ViT Classification": vit_output,
|
| 25 |
+
"CLIP Zero-Shot Classification": clip_output
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Optional: Example images from your project (use actual image paths or URLs)
|
| 29 |
+
example_images = [
|
| 30 |
+
["example_images/Chihiro_13.PNG"],
|
| 31 |
+
["example_images/000048.png"],
|
| 32 |
+
["example_images/000011.jpg"],
|
| 33 |
+
["example_images/000002.png."],
|
| 34 |
+
["example_images/Kiki_01.PNG"]
|
| 35 |
+
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
# Create Gradio interface
|
| 39 |
+
iface = gr.Interface(
|
| 40 |
+
fn=classify_character,
|
| 41 |
+
inputs=gr.Image(type="filepath"),
|
| 42 |
+
outputs=gr.JSON(),
|
| 43 |
+
title="Chihiro Classifier: ViT vs. CLIP",
|
| 44 |
+
description="Upload an image to see if it's Chihiro or not, using both a fine-tuned ViT model and CLIP zero-shot comparison.",
|
| 45 |
+
examples=example_images
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
iface.launch()
|
example_images/000002.png
ADDED
|
Git LFS Details
|
example_images/000011.jpg
ADDED
|
Git LFS Details
|
example_images/000048.png
ADDED
|
Git LFS Details
|
example_images/Chihiro_13.PNG
ADDED
|
|
Git LFS Details
|
example_images/Kiki_01.PNG
ADDED
|
|
Git LFS Details
|