Spaces:
Sleeping
Sleeping
Create modal_demo.txt
Browse files- modal_demo.txt +40 -0
modal_demo.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import modal
|
| 3 |
+
|
| 4 |
+
app = modal.App("gradio-app")
|
| 5 |
+
web_image = modal.Image.debian_slim(python_version="3.12").pip_install(
|
| 6 |
+
"fastapi[standard]==0.115.4",
|
| 7 |
+
"gradio~=5.7.1",
|
| 8 |
+
"pillow~=10.2.0",
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
@app.function(
|
| 12 |
+
image=web_image,
|
| 13 |
+
min_containers=1,
|
| 14 |
+
scaledown_window=60 * 20,
|
| 15 |
+
# gradio requires sticky sessions
|
| 16 |
+
# so we limit the number of concurrent containers to 1
|
| 17 |
+
# and allow it to scale to 100 concurrent inputs
|
| 18 |
+
max_containers=1,
|
| 19 |
+
)
|
| 20 |
+
@modal.concurrent(max_inputs=100)
|
| 21 |
+
@modal.asgi_app()
|
| 22 |
+
def ui():
|
| 23 |
+
|
| 24 |
+
import gradio as gr
|
| 25 |
+
from fastapi import FastAPI
|
| 26 |
+
from gradio.routes import mount_gradio_app
|
| 27 |
+
import time
|
| 28 |
+
|
| 29 |
+
def greet(name, intensity):
|
| 30 |
+
time.sleep(5) # Simulating processing time
|
| 31 |
+
return "Hello, " + name + "!" * int(intensity)
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=greet,
|
| 35 |
+
inputs=["text", "slider"],
|
| 36 |
+
outputs=["text"],
|
| 37 |
+
)
|
| 38 |
+
demo.queue(max_size=5) # Enable queue for handling multiple request
|
| 39 |
+
|
| 40 |
+
return mount_gradio_app(app=FastAPI(), blocks=demo, path="/")
|