Spaces:
Build error
Build error
Julien Simon
commited on
Commit
·
6ccbd18
1
Parent(s):
e0b3a35
Update
Browse files- app.py +9 -4
- requirements.txt +0 -1
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
import torch
|
4 |
|
|
|
5 |
# Check if CUDA is available
|
6 |
device = 0 if torch.cuda.is_available() else -1
|
7 |
|
@@ -22,11 +23,14 @@ model_names = [
|
|
22 |
# Cache for pipelines to avoid reloading models
|
23 |
pipelines = {}
|
24 |
|
|
|
25 |
def process(image_file, top_k):
|
26 |
labels = []
|
27 |
for m in model_names:
|
28 |
if m not in pipelines:
|
29 |
-
pipelines[m] = pipeline(
|
|
|
|
|
30 |
p = pipelines[m]
|
31 |
pred = p(image_file)
|
32 |
labels.append({x["label"]: x["score"] for x in pred[:top_k]})
|
@@ -41,9 +45,10 @@ top_k = gr.Slider(minimum=1, maximum=5, step=1, value=5, label="Top k classes")
|
|
41 |
labels = [gr.Label(label=m) for m in model_names]
|
42 |
|
43 |
description = (
|
44 |
-
"This Space compares popular image classifiers available on the
|
45 |
-
"including NAT and DINAT models. All models have
|
46 |
-
"The sample images were generated
|
|
|
47 |
)
|
48 |
|
49 |
iface = gr.Interface(
|
|
|
2 |
from transformers import pipeline
|
3 |
import torch
|
4 |
|
5 |
+
|
6 |
# Check if CUDA is available
|
7 |
device = 0 if torch.cuda.is_available() else -1
|
8 |
|
|
|
23 |
# Cache for pipelines to avoid reloading models
|
24 |
pipelines = {}
|
25 |
|
26 |
+
|
27 |
def process(image_file, top_k):
|
28 |
labels = []
|
29 |
for m in model_names:
|
30 |
if m not in pipelines:
|
31 |
+
pipelines[m] = pipeline(
|
32 |
+
"image-classification", model=m, device=device
|
33 |
+
)
|
34 |
p = pipelines[m]
|
35 |
pred = p(image_file)
|
36 |
labels.append({x["label"]: x["score"] for x in pred[:top_k]})
|
|
|
45 |
labels = [gr.Label(label=m) for m in model_names]
|
46 |
|
47 |
description = (
|
48 |
+
"This Space compares popular image classifiers available on the "
|
49 |
+
"Hugging Face hub, including NAT and DINAT models. All models have "
|
50 |
+
"been fine-tuned on ImageNet-1k. The sample images were generated "
|
51 |
+
"with Stable Diffusion."
|
52 |
)
|
53 |
|
54 |
iface = gr.Interface(
|
requirements.txt
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
torch==2.7.0
|
2 |
transformers==4.51.3
|
3 |
gradio>=3.50.0
|
4 |
-
--no-build-isolation
|
5 |
natten==0.17.5
|
6 |
Pillow>=9.0.0
|
|
|
1 |
torch==2.7.0
|
2 |
transformers==4.51.3
|
3 |
gradio>=3.50.0
|
|
|
4 |
natten==0.17.5
|
5 |
Pillow>=9.0.0
|