Spaces:
Runtime error
Runtime error
Commit
Β·
aef6fcf
1
Parent(s):
7cee370
Added app.py and example images
Browse files- 1945fieldnotesla00klau_0318.jpg +0 -0
- Journalsdateboo00DeanZ_0177.jpg +0 -0
- README.md +1 -1
- app.py +38 -0
- easternareacrui00natic_0004.jpg +0 -0
- newmexicobotani00newmb_0084.jpg +0 -0
- requirements.txt +4 -0
- sturmsfiguresofp01stur_0263.jpg +0 -0
1945fieldnotesla00klau_0318.jpg
ADDED
|
Journalsdateboo00DeanZ_0177.jpg
ADDED
|
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: Bhl Clip Classifier
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
|
|
|
| 1 |
---
|
| 2 |
title: Bhl Clip Classifier
|
| 3 |
+
emoji: π
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
checkpoint = "openai/clip-vit-base-patch32"
|
| 7 |
+
classifier = pipeline(model=checkpoint,
|
| 8 |
+
task="zero-shot-image-classification")
|
| 9 |
+
|
| 10 |
+
def shot(image, labels_text):
|
| 11 |
+
labels = labels_text.split(";")
|
| 12 |
+
results = classifier(image,
|
| 13 |
+
candidate_labels=labels)
|
| 14 |
+
return {result["label"]: result["score"] for result in results}
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(shot,
|
| 17 |
+
[gr.Image(type="pil"),
|
| 18 |
+
gr.Textbox(
|
| 19 |
+
label="Labels",
|
| 20 |
+
info="Separated by a semicolon (;)",
|
| 21 |
+
lines=6,
|
| 22 |
+
value="""A page of printed text;
|
| 23 |
+
A page of handwritten text;
|
| 24 |
+
A blank page with no text;
|
| 25 |
+
A cover of a book;
|
| 26 |
+
A page of a book that contains a large illustration;
|
| 27 |
+
A page that features a table with multiple columns and rows""",
|
| 28 |
+
)],
|
| 29 |
+
outputs="label",
|
| 30 |
+
examples=[['Journalsdateboo00DeanZ_0177.jpg',None],
|
| 31 |
+
["newmexicobotani00newmb_0084.jpg",None],
|
| 32 |
+
["easternareacrui00natic_0004.jpg",None],
|
| 33 |
+
["newmexicobotani00newmb_0084.jpg",None],
|
| 34 |
+
["sturmsfiguresofp01stur_0263.jpg",None]],
|
| 35 |
+
description="Upload an image of a scanned document page, or choose one of the examples below",
|
| 36 |
+
title="Zero-shot Image Classification of BHL Images")
|
| 37 |
+
|
| 38 |
+
demo.launch()
|
easternareacrui00natic_0004.jpg
ADDED
|
newmexicobotani00newmb_0084.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
pillow
|
| 4 |
+
numpy
|
sturmsfiguresofp01stur_0263.jpg
ADDED
|