Philipp Allgeuer
commited on
Commit
·
e0f4d55
1
Parent(s):
1c9b44b
Configure app visual appearance
Browse files- .gitattributes +1 -0
- README.md +39 -6
- app.py +65 -0
- requirements.txt +1 -0
- sample_images/01_rhodesian_ridgeback.jpg +3 -0
- sample_images/02_daffodil.jpg +3 -0
- sample_images/03_stuffed_toy.jpg +3 -0
- sample_images/04_banknote.jpg +3 -0
- sample_images/05_magic_lantern.jpg +3 -0
- sample_images/06_roof_rack.jpg +3 -0
- sample_images/07_armadillo.jpg +3 -0
- sample_images/08_church_aurora.jpg +3 -0
- sample_images/09_spur.jpg +3 -0
- sample_images/10_red_panda.jpg +3 -0
- sample_images/11_bicycle_rack.jpg +3 -0
- sample_images/12_pedestrian_crossing.jpg +3 -0
- sample_images/13_compression_bandage.jpg +3 -0
- sample_images/14_hearing_aid.jpg +3 -0
- sample_images/15_praying_mantis.jpg +3 -0
- sample_images/16_hippopotamus.jpg +3 -0
- sample_images/17_wreath.jpg +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ 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 |
+
sample_images/*.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,14 +1,47 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
|
|
|
| 7 |
sdk_version: 5.35.0
|
| 8 |
app_file: app.py
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: "NOVIC: Unconstrained Open Vocabulary Image Classification"
|
| 3 |
+
short_description: "Prompt-free open vocabulary classification of any image"
|
| 4 |
+
license: gpl-3.0
|
| 5 |
+
emoji: 🖼️
|
| 6 |
+
colorFrom: green
|
| 7 |
colorTo: yellow
|
| 8 |
sdk: gradio
|
| 9 |
+
python_version: 3.10
|
| 10 |
sdk_version: 5.35.0
|
| 11 |
app_file: app.py
|
| 12 |
+
fullWidth: true
|
| 13 |
+
header: default
|
| 14 |
+
models: []
|
| 15 |
+
tags:
|
| 16 |
+
- prompt-free
|
| 17 |
+
- open vocabulary
|
| 18 |
+
- image classification
|
| 19 |
+
- computer vision
|
| 20 |
+
- identification
|
| 21 |
+
- generative
|
| 22 |
+
pinned: true
|
| 23 |
+
disable_embedding: false
|
| 24 |
+
preload_from_hub: []
|
| 25 |
---
|
| 26 |
|
| 27 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 28 |
+
|
| 29 |
+
To run the Gradio space locally, you first create a sandboxed Python 3.10 environment:
|
| 30 |
+
```bash
|
| 31 |
+
python -m venv .venv # <-- Python 3.10
|
| 32 |
+
source .venv/bin/activate
|
| 33 |
+
# OR...
|
| 34 |
+
conda create -n novic_spaces python=3.10
|
| 35 |
+
conda activate novic_spaces
|
| 36 |
+
```
|
| 37 |
+
Then install `gradio` and any further requirements:
|
| 38 |
+
```bash
|
| 39 |
+
pip install gradio==5.35.0 -r requirements.txt
|
| 40 |
+
```
|
| 41 |
+
Now run the Gradio application:
|
| 42 |
+
```bash
|
| 43 |
+
./app.py
|
| 44 |
+
# OR...
|
| 45 |
+
gradio app.py
|
| 46 |
+
```
|
| 47 |
+
Open in a browser the URL that the application is running on (as shown in the CLI output), e.g. [http://127.0.0.1:7860](http://127.0.0.1:7860).
|
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# NOVIC Gradio Space
|
| 3 |
+
|
| 4 |
+
# Imports
|
| 5 |
+
import os
|
| 6 |
+
import glob
|
| 7 |
+
import random
|
| 8 |
+
from typing import Optional
|
| 9 |
+
import PIL.Image
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
# Sample images
|
| 13 |
+
IMAGE_EXTS = ('jpg', 'jpeg', 'png', 'webp')
|
| 14 |
+
SAMPLE_IMAGES = sorted(image_path for image_ext in IMAGE_EXTS for image_path in glob.glob(os.path.join('sample_images', f'*.{image_ext}')))
|
| 15 |
+
|
| 16 |
+
# Classify image
|
| 17 |
+
def classify_image(image: Optional[PIL.Image.Image]) -> dict[str, float]:
|
| 18 |
+
|
| 19 |
+
if image is None:
|
| 20 |
+
return {}
|
| 21 |
+
|
| 22 |
+
labels = ('thing', 'item', 'stuff', 'object', 'entity')
|
| 23 |
+
probs = [random.random() for _ in labels]
|
| 24 |
+
prob_sum = sum(probs)
|
| 25 |
+
return {label: prob / prob_sum for label, prob in zip(labels, probs)}
|
| 26 |
+
|
| 27 |
+
# Gradio UI
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=classify_image,
|
| 30 |
+
inputs=gr.Image(
|
| 31 |
+
height=400,
|
| 32 |
+
image_mode='RGB',
|
| 33 |
+
type='pil',
|
| 34 |
+
label='Input image',
|
| 35 |
+
show_label=True,
|
| 36 |
+
interactive=True,
|
| 37 |
+
show_fullscreen_button=True,
|
| 38 |
+
),
|
| 39 |
+
outputs=gr.Label(
|
| 40 |
+
num_top_classes=3,
|
| 41 |
+
label='Predicted label',
|
| 42 |
+
show_label=True,
|
| 43 |
+
show_heading=True,
|
| 44 |
+
),
|
| 45 |
+
examples=SAMPLE_IMAGES,
|
| 46 |
+
examples_per_page=20,
|
| 47 |
+
live=True,
|
| 48 |
+
title="🖼️ NOVIC: Unconstrained Open Vocabulary Image Classification",
|
| 49 |
+
description="*Select* an image from the examples shown below **OR** *Upload* an image file from your computer **OR** *Capture* an image using an attached camera **OR** *Copy-paste* an image from your clipboard. The label predictions on the right will update automatically!",
|
| 50 |
+
article=None,
|
| 51 |
+
theme=None,
|
| 52 |
+
flagging_mode='never',
|
| 53 |
+
analytics_enabled=True,
|
| 54 |
+
api_name='classify',
|
| 55 |
+
allow_duplication=False,
|
| 56 |
+
clear_btn=gr.Button(value='Clear', variant='secondary'),
|
| 57 |
+
show_progress='full',
|
| 58 |
+
fill_width=False,
|
| 59 |
+
deep_link=True,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Run demo
|
| 63 |
+
if __name__ == '__main__':
|
| 64 |
+
demo.launch()
|
| 65 |
+
# EOF
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pillow
|
sample_images/01_rhodesian_ridgeback.jpg
ADDED
|
Git LFS Details
|
sample_images/02_daffodil.jpg
ADDED
|
Git LFS Details
|
sample_images/03_stuffed_toy.jpg
ADDED
|
Git LFS Details
|
sample_images/04_banknote.jpg
ADDED
|
Git LFS Details
|
sample_images/05_magic_lantern.jpg
ADDED
|
Git LFS Details
|
sample_images/06_roof_rack.jpg
ADDED
|
Git LFS Details
|
sample_images/07_armadillo.jpg
ADDED
|
Git LFS Details
|
sample_images/08_church_aurora.jpg
ADDED
|
Git LFS Details
|
sample_images/09_spur.jpg
ADDED
|
Git LFS Details
|
sample_images/10_red_panda.jpg
ADDED
|
Git LFS Details
|
sample_images/11_bicycle_rack.jpg
ADDED
|
Git LFS Details
|
sample_images/12_pedestrian_crossing.jpg
ADDED
|
Git LFS Details
|
sample_images/13_compression_bandage.jpg
ADDED
|
Git LFS Details
|
sample_images/14_hearing_aid.jpg
ADDED
|
Git LFS Details
|
sample_images/15_praying_mantis.jpg
ADDED
|
Git LFS Details
|
sample_images/16_hippopotamus.jpg
ADDED
|
Git LFS Details
|
sample_images/17_wreath.jpg
ADDED
|
Git LFS Details
|