# https://www.gradio.app/guides/sharing-your-app#mounting-within-another-fast-api-app import gradio as gr import json import logging from PredictService import PredictService log_format = "[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s" logging.basicConfig(level=logging.INFO, format=log_format) logger = logging.getLogger() svc = PredictService() def api_classification(url): url_to_use = url if url_to_use == "exemple": url_to_use = "https://images.pexels.com/photos/326900/pexels-photo-326900.jpeg?cs=srgb&dl=pexels-pixabay-326900.jpg&fm=jpg" predictions = svc.predict(url_to_use) return json.dumps(predictions), url_to_use with gr.Blocks() as app: with gr.Tab("BioCLIP API"): with gr.Row(): with gr.Column(): # https://www.gradio.app/guides/key-component-concepts gr.HTML(value=""" This Gradio BioCLIP API is a BioCLIP based prediction.

origin is a BioCLIP DEMO discussion following pyBird MVP.
This endpoint is used by @botEnSky BlueSky bot.

How to use Gradio UI ?

How to use Gradio API (Node.js, Python, Bash Curl) ?

Credits

""", show_label=False) api_input = gr.Textbox( lines=1, label="Input a public image url", show_label=False, info="Add image url here.", value="https://natureconservancy-h.assetsadobe.com/is/image/content/dam/tnc/nature/en/photos/d/o/Downy-woodpecker-Matt-Williams.jpg?crop=0%2C39%2C3097%2C2322&wid=820&hei=615&scl=3.776829268292683" ) api_classification_btn = gr.Button("predict", variant="primary") api_classification_output_gallery = gr.Image(label="Input image used") with gr.Column(): api_classification_output_json = gr.JSON(label="This is classification result") # https://www.gradio.app/docs/gradio/json api_classification_btn.click( fn=api_classification, inputs=[api_input], outputs=[api_classification_output_json, api_classification_output_gallery], ) app.queue(max_size=20) app.launch()