|
import gradio as gr |
|
from fastapi import FastAPI |
|
from fastapi.staticfiles import StaticFiles |
|
|
|
|
|
|
|
def build_ui(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("## 🕹️ Motor Control – External JS") |
|
|
|
for i in range(6): |
|
gr.Slider( |
|
minimum=0, |
|
maximum=1, |
|
step=0.01, |
|
value=0, |
|
label=f"motor_{i}", |
|
elem_id=f"motor_{i}", |
|
) |
|
|
|
|
|
gr.HTML('<script src="/static/client.js"></script>') |
|
|
|
return demo |
|
|
|
|
|
demo = build_ui() |
|
|
|
|
|
app = FastAPI() |
|
app = gr.mount_gradio_app(app, demo, path="/") |
|
|
|
|
|
app.mount("/static", StaticFiles(directory="assets"), name="static") |
|
|
|
|
|
if __name__ == "__main__": |
|
import uvicorn |
|
|
|
uvicorn.run(app, host="0.0.0.0", port=7860) |
|
|