diff --git a/.gitignore b/.gitignore index 71c2798..b10be58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Byte-compiled / optimized / DLL files **/__pycache__/ +**/flagged/ *.py[cod] *$py.class *.pyc diff --git a/README.md b/README.md index df10c51..2617044 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,10 @@ Last of all the aim here is to keep up with the latest optimised foundation mode ## 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) ## Future updates diff --git a/app.py b/app.py new file mode 100644 index 0000000..34caf8f --- /dev/null +++ b/app.py @@ -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) diff --git a/clip/data/interstellar.jpg b/clip/data/interstellar.jpg new file mode 100644 index 0000000..c77b924 Binary files /dev/null and b/clip/data/interstellar.jpg differ diff --git a/images/gradio.png b/images/gradio.png new file mode 100644 index 0000000..8961c91 Binary files /dev/null and b/images/gradio.png differ diff --git a/requirements.txt b/requirements.txt index 3c75d87..71c20f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ ftfy==6.2.0 regex==2024.5.15 transformers==4.41.2 scipy==1.13.1 +gradio==3.26.0