Update app.py
Browse files
app.py
CHANGED
|
@@ -6,13 +6,13 @@ from generate import generate_music
|
|
| 6 |
# FASTAPI BACKEND
|
| 7 |
# ======================
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
@
|
| 12 |
-
def
|
| 13 |
return {"status": "running"}
|
| 14 |
|
| 15 |
-
@
|
| 16 |
def api_generate(prompt: str, duration: int = 10):
|
| 17 |
file = generate_music(prompt, duration)
|
| 18 |
return {"audio": file}
|
|
@@ -33,41 +33,37 @@ with gr.Blocks(
|
|
| 33 |
) as demo:
|
| 34 |
|
| 35 |
gr.Markdown("""
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
with gr.Row():
|
| 45 |
-
prompt = gr.Textbox(
|
| 46 |
-
label="Music Description",
|
| 47 |
-
placeholder="Soft emotional nasheed style, cinematic ambient..."
|
| 48 |
-
)
|
| 49 |
|
| 50 |
duration = gr.Slider(
|
| 51 |
-
5,
|
| 52 |
-
30,
|
| 53 |
value=10,
|
| 54 |
step=1,
|
| 55 |
label="Duration (seconds)"
|
| 56 |
)
|
| 57 |
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
-
label="Generated Audio",
|
| 62 |
-
type="filepath"
|
| 63 |
-
)
|
| 64 |
|
| 65 |
-
|
| 66 |
fn=ui_generate,
|
| 67 |
inputs=[prompt, duration],
|
| 68 |
-
outputs=
|
| 69 |
)
|
| 70 |
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# FASTAPI BACKEND
|
| 7 |
# ======================
|
| 8 |
|
| 9 |
+
api = FastAPI(title="AI Background Music Generator")
|
| 10 |
|
| 11 |
+
@api.get("/health")
|
| 12 |
+
def health():
|
| 13 |
return {"status": "running"}
|
| 14 |
|
| 15 |
+
@api.post("/generate")
|
| 16 |
def api_generate(prompt: str, duration: int = 10):
|
| 17 |
file = generate_music(prompt, duration)
|
| 18 |
return {"audio": file}
|
|
|
|
| 33 |
) as demo:
|
| 34 |
|
| 35 |
gr.Markdown("""
|
| 36 |
+
# 🎵 AI Background Music Generator
|
| 37 |
+
Generate royalty-free background music instantly.
|
| 38 |
+
""")
|
| 39 |
+
|
| 40 |
+
prompt = gr.Textbox(
|
| 41 |
+
label="Music Description",
|
| 42 |
+
placeholder="Soft cinematic nasheed style..."
|
| 43 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
duration = gr.Slider(
|
| 46 |
+
minimum=5,
|
| 47 |
+
maximum=30,
|
| 48 |
value=10,
|
| 49 |
step=1,
|
| 50 |
label="Duration (seconds)"
|
| 51 |
)
|
| 52 |
|
| 53 |
+
btn = gr.Button("Generate")
|
| 54 |
|
| 55 |
+
output = gr.Audio(type="filepath")
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
btn.click(
|
| 58 |
fn=ui_generate,
|
| 59 |
inputs=[prompt, duration],
|
| 60 |
+
outputs=output
|
| 61 |
)
|
| 62 |
|
| 63 |
|
| 64 |
+
# ======================
|
| 65 |
+
# IMPORTANT FIX
|
| 66 |
+
# ======================
|
| 67 |
+
# Mount GRADIO as ROOT APP
|
| 68 |
+
|
| 69 |
+
app = gr.mount_gradio_app(api, demo, path="/")
|