Download run.py from gradio/image_classifier_interface_load: direct link, hf CLI and curl.
- Browser
- Download file 828 Bytes
-
https://huggingface.co/spaces/gradio/image_classifier_interface_load/resolve/5505495540d045373e2fa0caa117ee38ec4e084e/run.py
- Command line
-
hf download hf://spaces/gradio/image_classifier_interface_load@5505495540d045373e2fa0caa117ee38ec4e084e/run.py
-
curl -L -o run.py https://huggingface.co/spaces/gradio/image_classifier_interface_load/resolve/5505495540d045373e2fa0caa117ee38ec4e084e/run.py
828 Bytes
| import gradio as gr | |
| import pathlib | |
| current_dir = pathlib.Path(__file__).parent | |
| images = [str(current_dir / "cheetah1.jpeg"), str(current_dir / "cheetah1.jpg"), str(current_dir / "lion.jpg")] | |
| img_classifier = gr.Interface.load( | |
| "models/google/vit-base-patch16-224", examples=images, cache_examples=False | |
| ) | |
| def func(img, text): | |
| return img_classifier(img), text | |
| using_img_classifier_as_function = gr.Interface( | |
| func, | |
| [gr.Image(type="filepath"), "text"], | |
| ["label", "text"], | |
| examples=[ | |
| [str(current_dir / "cheetah1.jpeg"), None], | |
| [str(current_dir / "cheetah1.jpg"), "cheetah"], | |
| [str(current_dir / "lion.jpg"), "lion"], | |
| ], | |
| cache_examples=False, | |
| ) | |
| demo = gr.TabbedInterface([using_img_classifier_as_function, img_classifier]) | |
| if __name__ == "__main__": | |
| demo.launch() |