Spaces:
Running
Running
| import modal | |
| app = modal.App("gradio-app") | |
| web_image = modal.Image.debian_slim(python_version="3.12").pip_install( | |
| "fastapi[standard]==0.115.4", | |
| "gradio~=5.7.1", | |
| "pillow~=10.2.0", | |
| ) | |
| @app.function( | |
| image=web_image, | |
| min_containers=1, | |
| scaledown_window=60 * 20, | |
| # gradio requires sticky sessions | |
| # so we limit the number of concurrent containers to 1 | |
| # and allow it to scale to 100 concurrent inputs | |
| max_containers=1, | |
| ) | |
| @modal.concurrent(max_inputs=100) | |
| @modal.asgi_app() | |
| def ui(): | |
| import gradio as gr | |
| from fastapi import FastAPI | |
| from gradio.routes import mount_gradio_app | |
| import time | |
| def greet(name, intensity): | |
| time.sleep(5) # Simulating processing time | |
| return "Hello, " + name + "!" * int(intensity) | |
| demo = gr.Interface( | |
| fn=greet, | |
| inputs=["text", "slider"], | |
| outputs=["text"], | |
| ) | |
| demo.queue(max_size=5) # Enable queue for handling multiple request | |
| return mount_gradio_app(app=FastAPI(), blocks=demo, path="/") | |