Spaces:
Sleeping
Sleeping
bsvaz
commited on
Commit
·
0dfac78
1
Parent(s):
03407d2
fix outputs
Browse files- .gradio/flagged/dataset1.csv +2 -0
- .gradio/flagged/image/b71cfb0c013a7fad3f6a/header_chiffre_0.jpg +0 -0
- __pycache__/classifier.cpython-312.pyc +0 -0
- __pycache__/custom_theme.cpython-312.pyc +0 -0
- app.py +10 -14
- classifier.py +15 -0
- custom_theme.py +18 -0
.gradio/flagged/dataset1.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
image,output,timestamp
|
| 2 |
+
.gradio/flagged/image/b71cfb0c013a7fad3f6a/header_chiffre_0.jpg,"{""label"": ""Sydney Harbour Bridge"", ""confidences"": [{""label"": ""Sydney Harbour Bridge"", ""confidence"": 0.997890055179596}, {""label"": ""Eiffel Tower"", ""confidence"": 0.9969549179077148}, {""label"": ""Forth Bridge"", ""confidence"": 0.905195415019989}, {""label"": ""Brooklyn Bridge"", ""confidence"": 0.9011015892028809}, {""label"": ""Monumento a la Revolucion"", ""confidence"": 0.8767676949501038}]}",2025-01-23 20:53:44.732426
|
.gradio/flagged/image/b71cfb0c013a7fad3f6a/header_chiffre_0.jpg
ADDED
|
__pycache__/classifier.cpython-312.pyc
ADDED
|
Binary file (1.79 kB). View file
|
|
|
__pycache__/custom_theme.cpython-312.pyc
ADDED
|
Binary file (777 Bytes). View file
|
|
|
app.py
CHANGED
|
@@ -1,22 +1,18 @@
|
|
| 1 |
-
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
classifier = pipeline("image-classification", model=model_name)
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
def classify_image(image):
|
| 10 |
-
results = classifier(image)
|
| 11 |
-
return {result["label"]: result["score"] for result in results}
|
| 12 |
-
|
| 13 |
-
# Create a Gradio interface
|
| 14 |
iface = gr.Interface(
|
| 15 |
-
fn=classify_image,
|
| 16 |
inputs=gr.Image(type="pil"),
|
| 17 |
-
outputs=
|
| 18 |
-
title="Image Classification",
|
| 19 |
-
description="Upload an image to
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from classifier import LandmarkClassifier
|
| 3 |
+
from custom_theme import custom_theme
|
| 4 |
|
| 5 |
+
# Initialize classifier
|
| 6 |
+
classifier = LandmarkClassifier()
|
|
|
|
| 7 |
|
| 8 |
+
# Create interface with Label component configured for dictionaries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
iface = gr.Interface(
|
| 10 |
+
fn=classifier.classify_image,
|
| 11 |
inputs=gr.Image(type="pil"),
|
| 12 |
+
outputs=gr.Label(num_top_classes=5),
|
| 13 |
+
title="Landmark Image Classification",
|
| 14 |
+
description="Upload an image to identify famous landmarks.",
|
| 15 |
+
theme=custom_theme # Apply the custom theme
|
| 16 |
)
|
| 17 |
|
| 18 |
iface.launch()
|
classifier.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
class LandmarkClassifier:
|
| 5 |
+
def __init__(self, model_name="bsvaz/landmark-classification-vit"):
|
| 6 |
+
self.model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 7 |
+
self.processor = AutoImageProcessor.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def classify_image(self, image):
|
| 10 |
+
inputs = self.processor(image, return_tensors="pt")
|
| 11 |
+
with torch.no_grad():
|
| 12 |
+
outputs = self.model(**inputs)
|
| 13 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 14 |
+
scores = probabilities[0].tolist()
|
| 15 |
+
return {self.model.config.id2label[i]: score for i, score in enumerate(scores)}
|
custom_theme.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Define a custom theme with purple as the main color and yellow for contrast
|
| 4 |
+
custom_theme = gr.themes.Default(
|
| 5 |
+
primary_hue="purple",
|
| 6 |
+
secondary_hue="yellow",
|
| 7 |
+
neutral_hue="gray",
|
| 8 |
+
).set(
|
| 9 |
+
body_background_fill='*primary_100', # Light purple background
|
| 10 |
+
body_text_color='*neutral_900', # Dark gray text for contrast
|
| 11 |
+
button_primary_background_fill='*primary_500', # Purple buttons
|
| 12 |
+
button_primary_text_color='white', # White text on buttons
|
| 13 |
+
button_primary_background_fill_hover='*primary_600', # Darker purple on hover
|
| 14 |
+
slider_color='*primary_500', # Purple slider
|
| 15 |
+
checkbox_background_color='*primary_500', # Purple checkbox
|
| 16 |
+
input_background_fill='*neutral_100', # Light gray input background
|
| 17 |
+
input_border_color='*primary_500', # Purple input border
|
| 18 |
+
)
|