mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-18 10:44:33 +08:00
921716f618
* fixed visibility error in notebooks in github * Delete fixNotebooks.py deleted script used to fix notebooks * Update generate_notebooks.py fixed a small bug that prevented visibility of notebooks in GitHub
2.0 KiB
2.0 KiB
Gradio Demo: image_classifier_interface_load¶
In [ ]:
!pip install -q gradio
In [ ]:
# Downloading files from the demo repo import os !wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_classifier_interface_load/cheetah1.jpeg !wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_classifier_interface_load/cheetah1.jpg !wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_classifier_interface_load/lion.jpg
In [ ]:
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.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()