Remove gr.Progress to fix HF Spaces compatibility
Browse files- app.py +0 -1
- src/ui/handlers.py +23 -114
app.py
CHANGED
|
@@ -153,5 +153,4 @@ if __name__ == "__main__":
|
|
| 153 |
server_name="0.0.0.0",
|
| 154 |
server_port=7860,
|
| 155 |
share=False,
|
| 156 |
-
theme=gr.themes.Soft(),
|
| 157 |
)
|
|
|
|
| 153 |
server_name="0.0.0.0",
|
| 154 |
server_port=7860,
|
| 155 |
share=False,
|
|
|
|
| 156 |
)
|
src/ui/handlers.py
CHANGED
|
@@ -2,12 +2,11 @@
|
|
| 2 |
Event Handlers
|
| 3 |
|
| 4 |
Handlers for all Gradio UI events.
|
| 5 |
-
Connects UI to services with
|
| 6 |
"""
|
| 7 |
|
| 8 |
import asyncio
|
| 9 |
from typing import Optional, Tuple
|
| 10 |
-
import gradio as gr
|
| 11 |
|
| 12 |
from ..services.music import MusicService
|
| 13 |
from ..services.image import ImageService
|
|
@@ -34,7 +33,7 @@ class Handlers:
|
|
| 34 |
"""
|
| 35 |
Collection of event handlers for the Gradio UI.
|
| 36 |
|
| 37 |
-
All handlers hide API complexity and provide clean
|
| 38 |
"""
|
| 39 |
|
| 40 |
@staticmethod
|
|
@@ -44,15 +43,9 @@ class Handlers:
|
|
| 44 |
instrumental: bool,
|
| 45 |
lyrics: str,
|
| 46 |
title: str,
|
| 47 |
-
api_key: str = ""
|
| 48 |
-
progress: gr.Progress = gr.Progress()
|
| 49 |
) -> Tuple[Optional[str], str]:
|
| 50 |
-
"""
|
| 51 |
-
Handle text-to-music generation.
|
| 52 |
-
|
| 53 |
-
Returns:
|
| 54 |
-
Tuple of (audio_path, status_message)
|
| 55 |
-
"""
|
| 56 |
if not prompt.strip():
|
| 57 |
return None, "Please enter a description for your music."
|
| 58 |
if not api_key.strip():
|
|
@@ -62,12 +55,6 @@ class Handlers:
|
|
| 62 |
service = MusicService(client=client)
|
| 63 |
|
| 64 |
try:
|
| 65 |
-
progress(0, desc="Starting music generation...")
|
| 66 |
-
|
| 67 |
-
def on_progress(value: float, message: str):
|
| 68 |
-
progress(value, desc=message)
|
| 69 |
-
|
| 70 |
-
# Run async in event loop
|
| 71 |
loop = asyncio.new_event_loop()
|
| 72 |
asyncio.set_event_loop(loop)
|
| 73 |
|
|
@@ -78,13 +65,11 @@ class Handlers:
|
|
| 78 |
title=title if title.strip() else None,
|
| 79 |
tags=tags if tags.strip() else None,
|
| 80 |
lyrics=lyrics if lyrics.strip() and not instrumental else None,
|
| 81 |
-
instrumental=instrumental
|
| 82 |
-
on_progress=on_progress
|
| 83 |
)
|
| 84 |
)
|
| 85 |
|
| 86 |
if clips:
|
| 87 |
-
# Download first clip
|
| 88 |
audio_path = loop.run_until_complete(
|
| 89 |
service.download_clip(clips[0])
|
| 90 |
)
|
|
@@ -107,15 +92,9 @@ class Handlers:
|
|
| 107 |
style_prompt: str,
|
| 108 |
tags: str,
|
| 109 |
title: str,
|
| 110 |
-
api_key: str = ""
|
| 111 |
-
progress: gr.Progress = gr.Progress()
|
| 112 |
) -> Tuple[Optional[str], str]:
|
| 113 |
-
"""
|
| 114 |
-
Handle cover song creation.
|
| 115 |
-
|
| 116 |
-
Returns:
|
| 117 |
-
Tuple of (audio_path, status_message)
|
| 118 |
-
"""
|
| 119 |
if not audio_file:
|
| 120 |
return None, "Please upload an audio file."
|
| 121 |
if not style_prompt.strip():
|
|
@@ -127,17 +106,10 @@ class Handlers:
|
|
| 127 |
service = MusicService(client=client)
|
| 128 |
|
| 129 |
try:
|
| 130 |
-
progress(0, desc="Processing audio file...")
|
| 131 |
-
|
| 132 |
-
def on_progress(value: float, message: str):
|
| 133 |
-
progress(value, desc=message)
|
| 134 |
-
|
| 135 |
loop = asyncio.new_event_loop()
|
| 136 |
asyncio.set_event_loop(loop)
|
| 137 |
|
| 138 |
try:
|
| 139 |
-
# For file upload, we need to use the file path as URL
|
| 140 |
-
# In production, you'd upload to a storage service first
|
| 141 |
audio_url = f"file://{audio_file}"
|
| 142 |
|
| 143 |
clips = loop.run_until_complete(
|
|
@@ -145,8 +117,7 @@ class Handlers:
|
|
| 145 |
audio_url=audio_url,
|
| 146 |
style_prompt=style_prompt,
|
| 147 |
title=title if title.strip() else None,
|
| 148 |
-
tags=tags if tags.strip() else None
|
| 149 |
-
on_progress=on_progress
|
| 150 |
)
|
| 151 |
)
|
| 152 |
|
|
@@ -170,15 +141,9 @@ class Handlers:
|
|
| 170 |
@staticmethod
|
| 171 |
def extract_stems(
|
| 172 |
audio_file: str,
|
| 173 |
-
api_key: str = ""
|
| 174 |
-
progress: gr.Progress = gr.Progress()
|
| 175 |
) -> Tuple[Optional[str], Optional[str], Optional[str], Optional[str], str]:
|
| 176 |
-
"""
|
| 177 |
-
Handle stem extraction.
|
| 178 |
-
|
| 179 |
-
Returns:
|
| 180 |
-
Tuple of (vocals_path, drums_path, bass_path, other_path, status_message)
|
| 181 |
-
"""
|
| 182 |
if not audio_file:
|
| 183 |
return None, None, None, None, "Please upload an audio file."
|
| 184 |
if not api_key.strip():
|
|
@@ -188,11 +153,6 @@ class Handlers:
|
|
| 188 |
service = MusicService(client=client)
|
| 189 |
|
| 190 |
try:
|
| 191 |
-
progress(0, desc="Analyzing audio...")
|
| 192 |
-
|
| 193 |
-
def on_progress(value: float, message: str):
|
| 194 |
-
progress(value, desc=message)
|
| 195 |
-
|
| 196 |
loop = asyncio.new_event_loop()
|
| 197 |
asyncio.set_event_loop(loop)
|
| 198 |
|
|
@@ -200,10 +160,7 @@ class Handlers:
|
|
| 200 |
audio_url = f"file://{audio_file}"
|
| 201 |
|
| 202 |
stems = loop.run_until_complete(
|
| 203 |
-
service.extract_stems(
|
| 204 |
-
audio_url=audio_url,
|
| 205 |
-
on_progress=on_progress
|
| 206 |
-
)
|
| 207 |
)
|
| 208 |
|
| 209 |
return (
|
|
@@ -228,15 +185,9 @@ class Handlers:
|
|
| 228 |
prompt: str,
|
| 229 |
style: str,
|
| 230 |
aspect_ratio: str,
|
| 231 |
-
api_key: str = ""
|
| 232 |
-
progress: gr.Progress = gr.Progress()
|
| 233 |
) -> Tuple[Optional[str], str]:
|
| 234 |
-
"""
|
| 235 |
-
Handle text-to-image generation.
|
| 236 |
-
|
| 237 |
-
Returns:
|
| 238 |
-
Tuple of (image_path, status_message)
|
| 239 |
-
"""
|
| 240 |
if not prompt.strip():
|
| 241 |
return None, "Please enter a description for your image."
|
| 242 |
if not api_key.strip():
|
|
@@ -246,11 +197,6 @@ class Handlers:
|
|
| 246 |
service = ImageService(client=client)
|
| 247 |
|
| 248 |
try:
|
| 249 |
-
progress(0, desc="Generating image...")
|
| 250 |
-
|
| 251 |
-
def on_progress(value: float, message: str):
|
| 252 |
-
progress(value, desc=message)
|
| 253 |
-
|
| 254 |
loop = asyncio.new_event_loop()
|
| 255 |
asyncio.set_event_loop(loop)
|
| 256 |
|
|
@@ -259,8 +205,7 @@ class Handlers:
|
|
| 259 |
service.generate_image(
|
| 260 |
prompt=prompt,
|
| 261 |
style=style,
|
| 262 |
-
aspect_ratio=aspect_ratio
|
| 263 |
-
on_progress=on_progress
|
| 264 |
)
|
| 265 |
)
|
| 266 |
|
|
@@ -286,15 +231,9 @@ class Handlers:
|
|
| 286 |
input_image: str,
|
| 287 |
edit_prompt: str,
|
| 288 |
strength: float,
|
| 289 |
-
api_key: str = ""
|
| 290 |
-
progress: gr.Progress = gr.Progress()
|
| 291 |
) -> Tuple[Optional[str], str]:
|
| 292 |
-
"""
|
| 293 |
-
Handle image-to-image editing.
|
| 294 |
-
|
| 295 |
-
Returns:
|
| 296 |
-
Tuple of (image_path, status_message)
|
| 297 |
-
"""
|
| 298 |
if not input_image:
|
| 299 |
return None, "Please upload an image."
|
| 300 |
if not edit_prompt.strip():
|
|
@@ -306,11 +245,6 @@ class Handlers:
|
|
| 306 |
service = ImageService(client=client)
|
| 307 |
|
| 308 |
try:
|
| 309 |
-
progress(0, desc="Processing image...")
|
| 310 |
-
|
| 311 |
-
def on_progress(value: float, message: str):
|
| 312 |
-
progress(value, desc=message)
|
| 313 |
-
|
| 314 |
loop = asyncio.new_event_loop()
|
| 315 |
asyncio.set_event_loop(loop)
|
| 316 |
|
|
@@ -321,8 +255,7 @@ class Handlers:
|
|
| 321 |
service.edit_image(
|
| 322 |
image_url=image_url,
|
| 323 |
edit_prompt=edit_prompt,
|
| 324 |
-
strength=strength
|
| 325 |
-
on_progress=on_progress
|
| 326 |
)
|
| 327 |
)
|
| 328 |
|
|
@@ -348,15 +281,9 @@ class Handlers:
|
|
| 348 |
prompt: str,
|
| 349 |
duration: int,
|
| 350 |
style: str,
|
| 351 |
-
api_key: str = ""
|
| 352 |
-
progress: gr.Progress = gr.Progress()
|
| 353 |
) -> Tuple[Optional[str], str]:
|
| 354 |
-
"""
|
| 355 |
-
Handle text-to-video generation.
|
| 356 |
-
|
| 357 |
-
Returns:
|
| 358 |
-
Tuple of (video_path, status_message)
|
| 359 |
-
"""
|
| 360 |
if not prompt.strip():
|
| 361 |
return None, "Please enter a description for your video."
|
| 362 |
if not api_key.strip():
|
|
@@ -366,11 +293,6 @@ class Handlers:
|
|
| 366 |
service = VideoService(client=client)
|
| 367 |
|
| 368 |
try:
|
| 369 |
-
progress(0, desc="Generating video...")
|
| 370 |
-
|
| 371 |
-
def on_progress(value: float, message: str):
|
| 372 |
-
progress(value, desc=message)
|
| 373 |
-
|
| 374 |
loop = asyncio.new_event_loop()
|
| 375 |
asyncio.set_event_loop(loop)
|
| 376 |
|
|
@@ -379,8 +301,7 @@ class Handlers:
|
|
| 379 |
service.generate_video(
|
| 380 |
prompt=prompt,
|
| 381 |
duration=int(duration),
|
| 382 |
-
style=style
|
| 383 |
-
on_progress=on_progress
|
| 384 |
)
|
| 385 |
)
|
| 386 |
|
|
@@ -406,15 +327,9 @@ class Handlers:
|
|
| 406 |
input_image: str,
|
| 407 |
motion_prompt: str,
|
| 408 |
duration: int,
|
| 409 |
-
api_key: str = ""
|
| 410 |
-
progress: gr.Progress = gr.Progress()
|
| 411 |
) -> Tuple[Optional[str], str]:
|
| 412 |
-
"""
|
| 413 |
-
Handle image-to-video animation.
|
| 414 |
-
|
| 415 |
-
Returns:
|
| 416 |
-
Tuple of (video_path, status_message)
|
| 417 |
-
"""
|
| 418 |
if not input_image:
|
| 419 |
return None, "Please upload an image."
|
| 420 |
if not motion_prompt.strip():
|
|
@@ -426,11 +341,6 @@ class Handlers:
|
|
| 426 |
service = VideoService(client=client)
|
| 427 |
|
| 428 |
try:
|
| 429 |
-
progress(0, desc="Animating image...")
|
| 430 |
-
|
| 431 |
-
def on_progress(value: float, message: str):
|
| 432 |
-
progress(value, desc=message)
|
| 433 |
-
|
| 434 |
loop = asyncio.new_event_loop()
|
| 435 |
asyncio.set_event_loop(loop)
|
| 436 |
|
|
@@ -441,8 +351,7 @@ class Handlers:
|
|
| 441 |
service.animate_image(
|
| 442 |
image_url=image_url,
|
| 443 |
motion_prompt=motion_prompt,
|
| 444 |
-
duration=int(duration)
|
| 445 |
-
on_progress=on_progress
|
| 446 |
)
|
| 447 |
)
|
| 448 |
|
|
|
|
| 2 |
Event Handlers
|
| 3 |
|
| 4 |
Handlers for all Gradio UI events.
|
| 5 |
+
Connects UI to services with error handling.
|
| 6 |
"""
|
| 7 |
|
| 8 |
import asyncio
|
| 9 |
from typing import Optional, Tuple
|
|
|
|
| 10 |
|
| 11 |
from ..services.music import MusicService
|
| 12 |
from ..services.image import ImageService
|
|
|
|
| 33 |
"""
|
| 34 |
Collection of event handlers for the Gradio UI.
|
| 35 |
|
| 36 |
+
All handlers hide API complexity and provide clean feedback.
|
| 37 |
"""
|
| 38 |
|
| 39 |
@staticmethod
|
|
|
|
| 43 |
instrumental: bool,
|
| 44 |
lyrics: str,
|
| 45 |
title: str,
|
| 46 |
+
api_key: str = ""
|
|
|
|
| 47 |
) -> Tuple[Optional[str], str]:
|
| 48 |
+
"""Handle text-to-music generation."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
if not prompt.strip():
|
| 50 |
return None, "Please enter a description for your music."
|
| 51 |
if not api_key.strip():
|
|
|
|
| 55 |
service = MusicService(client=client)
|
| 56 |
|
| 57 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
loop = asyncio.new_event_loop()
|
| 59 |
asyncio.set_event_loop(loop)
|
| 60 |
|
|
|
|
| 65 |
title=title if title.strip() else None,
|
| 66 |
tags=tags if tags.strip() else None,
|
| 67 |
lyrics=lyrics if lyrics.strip() and not instrumental else None,
|
| 68 |
+
instrumental=instrumental
|
|
|
|
| 69 |
)
|
| 70 |
)
|
| 71 |
|
| 72 |
if clips:
|
|
|
|
| 73 |
audio_path = loop.run_until_complete(
|
| 74 |
service.download_clip(clips[0])
|
| 75 |
)
|
|
|
|
| 92 |
style_prompt: str,
|
| 93 |
tags: str,
|
| 94 |
title: str,
|
| 95 |
+
api_key: str = ""
|
|
|
|
| 96 |
) -> Tuple[Optional[str], str]:
|
| 97 |
+
"""Handle cover song creation."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
if not audio_file:
|
| 99 |
return None, "Please upload an audio file."
|
| 100 |
if not style_prompt.strip():
|
|
|
|
| 106 |
service = MusicService(client=client)
|
| 107 |
|
| 108 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
loop = asyncio.new_event_loop()
|
| 110 |
asyncio.set_event_loop(loop)
|
| 111 |
|
| 112 |
try:
|
|
|
|
|
|
|
| 113 |
audio_url = f"file://{audio_file}"
|
| 114 |
|
| 115 |
clips = loop.run_until_complete(
|
|
|
|
| 117 |
audio_url=audio_url,
|
| 118 |
style_prompt=style_prompt,
|
| 119 |
title=title if title.strip() else None,
|
| 120 |
+
tags=tags if tags.strip() else None
|
|
|
|
| 121 |
)
|
| 122 |
)
|
| 123 |
|
|
|
|
| 141 |
@staticmethod
|
| 142 |
def extract_stems(
|
| 143 |
audio_file: str,
|
| 144 |
+
api_key: str = ""
|
|
|
|
| 145 |
) -> Tuple[Optional[str], Optional[str], Optional[str], Optional[str], str]:
|
| 146 |
+
"""Handle stem extraction."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
if not audio_file:
|
| 148 |
return None, None, None, None, "Please upload an audio file."
|
| 149 |
if not api_key.strip():
|
|
|
|
| 153 |
service = MusicService(client=client)
|
| 154 |
|
| 155 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
loop = asyncio.new_event_loop()
|
| 157 |
asyncio.set_event_loop(loop)
|
| 158 |
|
|
|
|
| 160 |
audio_url = f"file://{audio_file}"
|
| 161 |
|
| 162 |
stems = loop.run_until_complete(
|
| 163 |
+
service.extract_stems(audio_url=audio_url)
|
|
|
|
|
|
|
|
|
|
| 164 |
)
|
| 165 |
|
| 166 |
return (
|
|
|
|
| 185 |
prompt: str,
|
| 186 |
style: str,
|
| 187 |
aspect_ratio: str,
|
| 188 |
+
api_key: str = ""
|
|
|
|
| 189 |
) -> Tuple[Optional[str], str]:
|
| 190 |
+
"""Handle text-to-image generation."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
if not prompt.strip():
|
| 192 |
return None, "Please enter a description for your image."
|
| 193 |
if not api_key.strip():
|
|
|
|
| 197 |
service = ImageService(client=client)
|
| 198 |
|
| 199 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
loop = asyncio.new_event_loop()
|
| 201 |
asyncio.set_event_loop(loop)
|
| 202 |
|
|
|
|
| 205 |
service.generate_image(
|
| 206 |
prompt=prompt,
|
| 207 |
style=style,
|
| 208 |
+
aspect_ratio=aspect_ratio
|
|
|
|
| 209 |
)
|
| 210 |
)
|
| 211 |
|
|
|
|
| 231 |
input_image: str,
|
| 232 |
edit_prompt: str,
|
| 233 |
strength: float,
|
| 234 |
+
api_key: str = ""
|
|
|
|
| 235 |
) -> Tuple[Optional[str], str]:
|
| 236 |
+
"""Handle image-to-image editing."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
if not input_image:
|
| 238 |
return None, "Please upload an image."
|
| 239 |
if not edit_prompt.strip():
|
|
|
|
| 245 |
service = ImageService(client=client)
|
| 246 |
|
| 247 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
loop = asyncio.new_event_loop()
|
| 249 |
asyncio.set_event_loop(loop)
|
| 250 |
|
|
|
|
| 255 |
service.edit_image(
|
| 256 |
image_url=image_url,
|
| 257 |
edit_prompt=edit_prompt,
|
| 258 |
+
strength=strength
|
|
|
|
| 259 |
)
|
| 260 |
)
|
| 261 |
|
|
|
|
| 281 |
prompt: str,
|
| 282 |
duration: int,
|
| 283 |
style: str,
|
| 284 |
+
api_key: str = ""
|
|
|
|
| 285 |
) -> Tuple[Optional[str], str]:
|
| 286 |
+
"""Handle text-to-video generation."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
if not prompt.strip():
|
| 288 |
return None, "Please enter a description for your video."
|
| 289 |
if not api_key.strip():
|
|
|
|
| 293 |
service = VideoService(client=client)
|
| 294 |
|
| 295 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
loop = asyncio.new_event_loop()
|
| 297 |
asyncio.set_event_loop(loop)
|
| 298 |
|
|
|
|
| 301 |
service.generate_video(
|
| 302 |
prompt=prompt,
|
| 303 |
duration=int(duration),
|
| 304 |
+
style=style
|
|
|
|
| 305 |
)
|
| 306 |
)
|
| 307 |
|
|
|
|
| 327 |
input_image: str,
|
| 328 |
motion_prompt: str,
|
| 329 |
duration: int,
|
| 330 |
+
api_key: str = ""
|
|
|
|
| 331 |
) -> Tuple[Optional[str], str]:
|
| 332 |
+
"""Handle image-to-video animation."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
if not input_image:
|
| 334 |
return None, "Please upload an image."
|
| 335 |
if not motion_prompt.strip():
|
|
|
|
| 341 |
service = VideoService(client=client)
|
| 342 |
|
| 343 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
loop = asyncio.new_event_loop()
|
| 345 |
asyncio.set_event_loop(loop)
|
| 346 |
|
|
|
|
| 351 |
service.animate_image(
|
| 352 |
image_url=image_url,
|
| 353 |
motion_prompt=motion_prompt,
|
| 354 |
+
duration=int(duration)
|
|
|
|
| 355 |
)
|
| 356 |
)
|
| 357 |
|