Spaces:
Sleeping
Sleeping
Deploy HARP wrapper via model agent
Browse files- .harp/manifest.json +27 -0
- README.md +13 -7
- app.py +114 -0
- requirements.txt +3 -0
.harp/manifest.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend_space": "facebook/MelodyFlow",
|
| 3 |
+
"deploy_mode": "remote-backend",
|
| 4 |
+
"entry": "app.py",
|
| 5 |
+
"framework": "gradio_client",
|
| 6 |
+
"generated": true,
|
| 7 |
+
"io": {
|
| 8 |
+
"inputs": [
|
| 9 |
+
"textbox",
|
| 10 |
+
"slider",
|
| 11 |
+
"slider",
|
| 12 |
+
"checkbox",
|
| 13 |
+
"slider",
|
| 14 |
+
"slider",
|
| 15 |
+
"audio"
|
| 16 |
+
],
|
| 17 |
+
"outputs": [
|
| 18 |
+
"audio",
|
| 19 |
+
"audio",
|
| 20 |
+
"audio"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
"repo_id": "facebook/MelodyFlow",
|
| 24 |
+
"source": "recipe",
|
| 25 |
+
"space_layout": "huggingface-gradio",
|
| 26 |
+
"task": "custom"
|
| 27 |
+
}
|
README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
title: Melodyflow
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: "Melodyflow"
|
| 3 |
+
colorFrom: indigo
|
| 4 |
+
colorTo: gray
|
|
|
|
| 5 |
sdk: gradio
|
| 6 |
+
sdk_version: 5.28.0
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
+
license: "other"
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Melodyflow
|
| 13 |
+
|
| 14 |
+
TODO: describe this model.
|
| 15 |
+
|
| 16 |
+
- Inputs: textbox, slider, slider, checkbox, slider, slider, audio
|
| 17 |
+
- Outputs: audio, audio, audio
|
| 18 |
+
|
| 19 |
+
Generated by the HARP model agent from a recipe.
|
app.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
from pyharp import *
|
| 8 |
+
from gradio_client import Client, handle_file
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
_BACKEND_SPACE = "facebook/MelodyFlow"
|
| 12 |
+
_BACKEND_API_NAME = "/predict"
|
| 13 |
+
_BACKEND_TOKEN_ENV = "HF_TOKEN"
|
| 14 |
+
_ACCEPT_USER_TOKEN = True
|
| 15 |
+
_client = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _backend_client():
|
| 19 |
+
# Lazily create and cache one warm connection using this Space's own
|
| 20 |
+
# token (from the HF_TOKEN secret) or anonymous if none is set. User
|
| 21 |
+
# tokens are NOT cached here -- they get a fresh per-call connection.
|
| 22 |
+
global _client
|
| 23 |
+
if _client is None:
|
| 24 |
+
_token = os.environ.get(_BACKEND_TOKEN_ENV) or None
|
| 25 |
+
_client = Client(_BACKEND_SPACE, hf_token=_token)
|
| 26 |
+
return _client
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _quota_hint(message):
|
| 30 |
+
# Turn a backend ZeroGPU quota error into an actionable message.
|
| 31 |
+
# NOTE: 'message' is the backend's error text; it never contains our token.
|
| 32 |
+
_low = (message or "").lower()
|
| 33 |
+
if "quota" in _low or "zerogpu" in _low:
|
| 34 |
+
if _ACCEPT_USER_TOKEN:
|
| 35 |
+
return (
|
| 36 |
+
"The backend's ZeroGPU quota is exhausted for the identity making "
|
| 37 |
+
"this call. Paste your own Hugging Face token in the token field "
|
| 38 |
+
"(read scope) so usage is attributed to your account."
|
| 39 |
+
)
|
| 40 |
+
return (
|
| 41 |
+
"The backend's ZeroGPU quota is exhausted. This Space's calls are "
|
| 42 |
+
"anonymous unless an HF_TOKEN secret is set (Settings -> Variables "
|
| 43 |
+
"and secrets); use a token from a PRO account or a ZeroGPU-enabled org."
|
| 44 |
+
)
|
| 45 |
+
return message or "Backend call failed."
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
model_card = ModelCard(
|
| 49 |
+
name="Melodyflow",
|
| 50 |
+
description="TODO: describe this model.",
|
| 51 |
+
author="facebook",
|
| 52 |
+
tags=[],
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def process_fn(text, steps, target_flowstep, regularize, regularization_strength, duration, melody, _hf_user_token=''):
|
| 57 |
+
_tok = (_hf_user_token or '').strip()
|
| 58 |
+
if _tok:
|
| 59 |
+
_conn = Client(_BACKEND_SPACE, hf_token=_tok)
|
| 60 |
+
else:
|
| 61 |
+
_conn = _backend_client()
|
| 62 |
+
try:
|
| 63 |
+
_raw = _conn.predict(
|
| 64 |
+
'facebook/melodyflow-t24-30secs',
|
| 65 |
+
text,
|
| 66 |
+
'midpoint',
|
| 67 |
+
steps,
|
| 68 |
+
target_flowstep,
|
| 69 |
+
regularize,
|
| 70 |
+
regularization_strength,
|
| 71 |
+
duration,
|
| 72 |
+
handle_file(melody),
|
| 73 |
+
api_name="/predict",
|
| 74 |
+
)
|
| 75 |
+
except Exception as _exc: # surface a token-aware hint, never the token
|
| 76 |
+
raise gr.Error(_quota_hint(str(_exc)))
|
| 77 |
+
_values = list(_raw) if isinstance(_raw, (list, tuple)) else [_raw]
|
| 78 |
+
_detail = " | ".join(str(_v) for _v in _values if isinstance(_v, str) and _v.strip())
|
| 79 |
+
_out_generated_audio_variation_1 = _values[0] if len(_values) > 0 else None
|
| 80 |
+
if not _out_generated_audio_variation_1:
|
| 81 |
+
raise gr.Error(_detail or "The backend Space returned no 'generated_audio_variation_1' output. Check the backend Space's logs; if it uses ZeroGPU it may need a moment to warm up.")
|
| 82 |
+
_out_generated_audio_variation_2 = _values[1] if len(_values) > 1 else None
|
| 83 |
+
if not _out_generated_audio_variation_2:
|
| 84 |
+
raise gr.Error(_detail or "The backend Space returned no 'generated_audio_variation_2' output. Check the backend Space's logs; if it uses ZeroGPU it may need a moment to warm up.")
|
| 85 |
+
_out_generated_audio_variation_3 = _values[2] if len(_values) > 2 else None
|
| 86 |
+
if not _out_generated_audio_variation_3:
|
| 87 |
+
raise gr.Error(_detail or "The backend Space returned no 'generated_audio_variation_3' output. Check the backend Space's logs; if it uses ZeroGPU it may need a moment to warm up.")
|
| 88 |
+
return _out_generated_audio_variation_1, _out_generated_audio_variation_2, _out_generated_audio_variation_3
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
with gr.Blocks() as demo:
|
| 92 |
+
input_components = [
|
| 93 |
+
gr.Textbox(label="Input Text"),
|
| 94 |
+
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=128.0, label="Inference steps"),
|
| 95 |
+
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0.0, label="Target Flow step"),
|
| 96 |
+
gr.Checkbox(value=False, label="Regularize"),
|
| 97 |
+
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0.2, label="Regularization Strength"),
|
| 98 |
+
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=30.0, label="Duration"),
|
| 99 |
+
gr.Audio(type="filepath", label="File or Microphone"),
|
| 100 |
+
gr.Textbox(label="Hugging Face token (optional)", type="password", info="Optional. Paste a Hugging Face token (Settings -> Access Tokens, read scope) so ZeroGPU usage on the backend is charged to YOUR account. Used only for this call; not stored. Leave blank to use this Space's own token."),
|
| 101 |
+
]
|
| 102 |
+
output_components = [
|
| 103 |
+
gr.Audio(type="filepath", label="Generated Audio - variation 1"),
|
| 104 |
+
gr.Audio(type="filepath", label="Generated Audio - variation 2"),
|
| 105 |
+
gr.Audio(type="filepath", label="Generated Audio - variation 3"),
|
| 106 |
+
]
|
| 107 |
+
build_endpoint(
|
| 108 |
+
model_card=model_card,
|
| 109 |
+
input_components=input_components,
|
| 110 |
+
output_components=output_components,
|
| 111 |
+
process_fn=process_fn,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
demo.queue().launch(share=True, show_error=False, pwa=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git+https://github.com/TEAMuP-dev/pyharp.git@v0.3.0
|
| 2 |
+
gradio>=4.0
|
| 3 |
+
gradio_client
|