Spaces:
Sleeping
Sleeping
added the style fix to the js
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
# ✅ Create FastAPI App
|
| 6 |
app = FastAPI()
|
|
@@ -20,7 +21,8 @@ navigator.requestMIDIAccess()
|
|
| 20 |
// ✅ Dummy Button Function
|
| 21 |
function sendMIDI() {
|
| 22 |
console.log("🎹 Sending Test MIDI Note");
|
| 23 |
-
|
|
|
|
| 24 |
method: "POST",
|
| 25 |
headers: { "Content-Type": "application/json" },
|
| 26 |
body: JSON.stringify({ note: 60, velocity: 100 })
|
|
@@ -46,16 +48,16 @@ function sendMIDI() {
|
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
gr.HTML(midi_js)
|
| 48 |
|
| 49 |
-
# ✅ Mount
|
| 50 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 51 |
|
| 52 |
-
# ✅
|
| 53 |
-
@app.post("/midi_input")
|
| 54 |
async def process_midi(request: Request):
|
| 55 |
data = await request.json()
|
| 56 |
return {"status": "success", "received_note": data["note"], "received_velocity": data["velocity"]}
|
| 57 |
|
|
|
|
| 58 |
if __name__ == "__main__":
|
| 59 |
-
import uvicorn
|
| 60 |
print("🚀 Starting FastAPI with Gradio...")
|
| 61 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
import json
|
| 4 |
+
import uvicorn
|
| 5 |
|
| 6 |
# ✅ Create FastAPI App
|
| 7 |
app = FastAPI()
|
|
|
|
| 21 |
// ✅ Dummy Button Function
|
| 22 |
function sendMIDI() {
|
| 23 |
console.log("🎹 Sending Test MIDI Note");
|
| 24 |
+
|
| 25 |
+
fetch("/api/midi_input", { // ✅ Fix: Use /api prefix
|
| 26 |
method: "POST",
|
| 27 |
headers: { "Content-Type": "application/json" },
|
| 28 |
body: JSON.stringify({ note: 60, velocity: 100 })
|
|
|
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
gr.HTML(midi_js)
|
| 50 |
|
| 51 |
+
# ✅ Mount Gradio on a separate path (prevents API conflicts)
|
| 52 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 53 |
|
| 54 |
+
# ✅ Define FastAPI Endpoint (Fixing Not Found Issue)
|
| 55 |
+
@app.post("/api/midi_input") # ✅ Fix: Ensure endpoint is under /api
|
| 56 |
async def process_midi(request: Request):
|
| 57 |
data = await request.json()
|
| 58 |
return {"status": "success", "received_note": data["note"], "received_velocity": data["velocity"]}
|
| 59 |
|
| 60 |
+
# ✅ Run FastAPI & Gradio Server
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 62 |
print("🚀 Starting FastAPI with Gradio...")
|
| 63 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|