-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from rhysdg/feat-gradio-app
Feat - Example Gradio app
- Loading branch information
Showing
6 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Byte-compiled / optimized / DLL files | ||
**/__pycache__/ | ||
**/flagged/ | ||
*.py[cod] | ||
*$py.class | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import gradio as gr | ||
from PIL import Image | ||
from clip.model import OnnxClip, softmax, get_similarity_scores | ||
|
||
example = ["a photo of space", | ||
"a photo of a man", | ||
"a photo of a man in dungarees", | ||
"a photo of a sad man in dungarees", | ||
"a photo of a sad man in dungarees with short hair and orange container to the right", | ||
"a photo of a sad man in dungarees with short hair", | ||
"a photo of a happy man in dungarees", | ||
"A photo of Christopher Nolan"] | ||
|
||
|
||
def classify(image, text): | ||
images = [image] | ||
|
||
|
||
texts = {"classification": text.split(',') | ||
} | ||
|
||
#type='clip' is also avvaiilable with this usage | ||
onnx_model = OnnxClip(batch_size=16, type='siglip_full') | ||
probs, _ = onnx_model.inference(images, texts) | ||
|
||
return {label: prob for label, prob in zip(texts['classification'], probs['classification'])} | ||
|
||
|
||
demo = gr.Interface( | ||
classify, | ||
[ | ||
gr.Image(label="Image", type="pil"), | ||
gr.Textbox(label="Labels", info="Comma-separated list of class labels"), | ||
], | ||
gr.Label(label="Result"), | ||
examples=[['clip/data/interstellar.jpg', ','.join(example)]], | ||
) | ||
try: | ||
demo.launch(debug=True, height=1000) | ||
except Exception: | ||
demo.launch(share=True, debug=True, height=1000) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ ftfy==6.2.0 | |
regex==2024.5.15 | ||
transformers==4.41.2 | ||
scipy==1.13.1 | ||
gradio==3.26.0 |