gradio/demo/image_classifier_interface_load/run.py
Abubakar Abid 6e6121a1ac
Sets up the Python gradio client (#3300)
* placeholder

* changelog

* added to readme

* client

* implement futures

* utils

* scripts

* lint

* reorg

* scripts

* serialization

* cleanup

* fns

* serialize

* cache

* callbacks

* updates

* formatting

* packaging

* requirements

* remove changelog

* client

* access token

* formatting

* deprecate

* format backend

* client replace

* updates

* moving from utils

* remove code duplication

* rm duplicates

* simplify

* galleryserializer

* serializable

* load serializers

* fixing errors

* errors

* typing

* tests

* changelog

* lint

* fix lint

* fixing files

* formatting

* type

* fix type checking

* changelog

* changelog

* Update client/python/gradio_client/client.py

Co-authored-by: Lucain <lucainp@gmail.com>

* formatting, tests

* formatting, tests

* gr.load

* refactoring

* refactoring'

* formatting

* formatting

* tests

* tests

* fix tests

* cleanup

* added tests

* adding scripts

* formatting

* address review comments

* readme

* serialize info

* remove from changelog

* version 0.0.2 released

* lint

* type fix

* check

* type issues

* hf_token

* update hf token

* telemetry

* docs, circle dependency

* hf token

* formatting

* updates

* sort

* script

* external

* docs

* formatting

* fixes

* scripts

* requirements

* fix tests

* context

* changes

* formatting

* fixes

* format fix

---------

Co-authored-by: Lucain <lucainp@gmail.com>
2023-03-23 15:33:44 -07:00

32 lines
818 B
Python

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()