import logging import gradio as gr import uvicorn from fastapi import FastAPI import routes from helpers import formatters, session_logger session_logger.change_logging() app = FastAPI(title="fastapi_with_gradio...", version="1.0") logging.info("FastAPI app created, including routes...") app.include_router(routes.router) logging.info("routes included, creating gradio app") CUSTOM_GRADIO_PATH = "/" io = gr.Interface( formatters.request_formatter, inputs=[ gr.Textbox(lines=1, placeholder="10", label="write a number to divide 100; 0 will raise ZeroDivisionError"), ], outputs=[ gr.Textbox(lines=1, placeholder=None, label="Text Output"), ], title="gradio with fastapi...", ) logging.info("mounting gradio app within FastAPI...") app = gr.mount_gradio_app(app, io, path=CUSTOM_GRADIO_PATH) logging.info("gradio app mounted") if __name__ == '__main__': uvicorn.run(app, host="0.0.0.0", port=7860)