Skip to content

Commit

Permalink
Merge pull request #5 from rhysdg/feat-gradio-app
Browse files Browse the repository at this point in the history
Feat - Example Gradio app
  • Loading branch information
rhysdg authored Jun 21, 2024
2 parents 37b9be9 + b8868a3 commit 1de0332
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
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
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ Last of all the aim here is to keep up with the latest optimised foundation mode

<!-- PROPOSED UPDATES -->
## Latest Updates
- Pending
- Added a Gradio example app. Ignore the percentages for now - the results of simgoid outputs don't sum to 1 in concert. The results however are pretty impressive! - simply run `python3 app.py` from your root and head to `http://127.0.0.1:7860/`


![alt text](images/gradio.png)

<!-- PROPOSED UPDATES -->
## Future updates
Expand Down
41 changes: 41 additions & 0 deletions app.py
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)
Binary file added clip/data/interstellar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gradio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ftfy==6.2.0
regex==2024.5.15
transformers==4.41.2
scipy==1.13.1
gradio==3.26.0

0 comments on commit 1de0332

Please sign in to comment.