gradio/demo/image_classifier_interface_load/run.py
Freddy Boulton 8e24d5d646
Deploy All Demos to Spaces on PRs (#2012)
* Add step to deploy to spaces on release

* Import package not modules

* Lint

* Hacky solution

* Add app file

* Github actions script

* Fix bucket url

* Update versioning

* Fic typo in script

* Change path

* Fix quote

* Clean up action

* Fix keys

* Formatting + comment

* Fix all_demo creation

* lint ui

* Get latest pypi version and use only 20 demos

* Test version change works correctly

* Fix gradio version

* Fix typo

* Use github sha to rebuild on every commit

* Get sha the proper way

* Change where env is accessed

* Fix typo in cp

* Undo changes to version.txt

* Add matrix transpose
2022-08-16 12:07:20 -04:00

33 lines
790 B
Python

import gradio as gr
import pathlib
current_dir = pathlib.Path(__file__)
images = [current_dir / "cheetah1.jpeg", current_dir / "cheetah1.jpg", current_dir / "lion.jpg"]
img_classifier = gr.Interface.load(
"models/google/vit-base-patch16-224", examples=images, cache_examples=True
)
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=[
[current_dir / "cheetah1.jpeg", None],
[current_dir / "cheetah1.jpg", "cheetah"],
[current_dir / "lion.jpg", "lion"],
],
cache_examples=True,
)
demo = gr.TabbedInterface([using_img_classifier_as_function, img_classifier])
if __name__ == "__main__":
demo.launch()