Full app with import error handling
Browse files
app.py
CHANGED
|
@@ -1,8 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo =
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
StackNet Demo
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
# Test import of our modules
|
| 8 |
+
try:
|
| 9 |
+
from src.ui.tabs import create_all_tabs
|
| 10 |
+
from src.ui.handlers import Handlers
|
| 11 |
+
MODULES_OK = True
|
| 12 |
+
except Exception as e:
|
| 13 |
+
MODULES_OK = False
|
| 14 |
+
IMPORT_ERROR = str(e)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def create_demo():
|
| 18 |
+
with gr.Blocks(title="StackNet Demo") as demo:
|
| 19 |
+
gr.Markdown("# StackNet Demo 1:1 Preview")
|
| 20 |
+
|
| 21 |
+
if not MODULES_OK:
|
| 22 |
+
gr.Markdown(f"**Import Error:** {IMPORT_ERROR}")
|
| 23 |
+
return demo
|
| 24 |
+
|
| 25 |
+
with gr.Accordion("Settings", open=False):
|
| 26 |
+
api_key = gr.Textbox(
|
| 27 |
+
label="StackNet Key",
|
| 28 |
+
placeholder="Enter your key (e.g., sn_xxxx...)",
|
| 29 |
+
type="password",
|
| 30 |
+
value=""
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
with gr.Tabs():
|
| 34 |
+
tabs = create_all_tabs()
|
| 35 |
+
|
| 36 |
+
# Text to Music
|
| 37 |
+
ttm = tabs["text_to_music"]
|
| 38 |
+
ttm["generate_btn"].click(
|
| 39 |
+
fn=Handlers.generate_music,
|
| 40 |
+
inputs=[
|
| 41 |
+
ttm["prompt"],
|
| 42 |
+
ttm["tags"],
|
| 43 |
+
ttm["instrumental"],
|
| 44 |
+
ttm["lyrics"],
|
| 45 |
+
ttm["title"],
|
| 46 |
+
api_key
|
| 47 |
+
],
|
| 48 |
+
outputs=[ttm["output_audio"], ttm["status"]]
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Music to Music - Cover
|
| 52 |
+
mtm = tabs["music_to_music"]
|
| 53 |
+
mtm["cover_btn"].click(
|
| 54 |
+
fn=Handlers.create_cover,
|
| 55 |
+
inputs=[
|
| 56 |
+
mtm["cover_audio_input"],
|
| 57 |
+
mtm["cover_style_prompt"],
|
| 58 |
+
mtm["cover_tags"],
|
| 59 |
+
mtm["cover_title"],
|
| 60 |
+
api_key
|
| 61 |
+
],
|
| 62 |
+
outputs=[mtm["cover_output"], mtm["cover_status"]]
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
# Music to Music - Stems
|
| 66 |
+
mtm["stems_btn"].click(
|
| 67 |
+
fn=Handlers.extract_stems,
|
| 68 |
+
inputs=[mtm["stems_audio_input"], api_key],
|
| 69 |
+
outputs=[
|
| 70 |
+
mtm["vocals_output"],
|
| 71 |
+
mtm["drums_output"],
|
| 72 |
+
mtm["bass_output"],
|
| 73 |
+
mtm["other_output"],
|
| 74 |
+
mtm["stems_status"]
|
| 75 |
+
]
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# Text to Image
|
| 79 |
+
tti = tabs["text_to_image"]
|
| 80 |
+
tti["generate_btn"].click(
|
| 81 |
+
fn=Handlers.generate_image,
|
| 82 |
+
inputs=[
|
| 83 |
+
tti["prompt"],
|
| 84 |
+
tti["style"],
|
| 85 |
+
tti["aspect_ratio"],
|
| 86 |
+
api_key
|
| 87 |
+
],
|
| 88 |
+
outputs=[tti["output_image"], tti["status"]]
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
# Image to Image
|
| 92 |
+
iti = tabs["image_to_image"]
|
| 93 |
+
iti["edit_btn"].click(
|
| 94 |
+
fn=Handlers.edit_image,
|
| 95 |
+
inputs=[
|
| 96 |
+
iti["input_image"],
|
| 97 |
+
iti["edit_prompt"],
|
| 98 |
+
iti["strength"],
|
| 99 |
+
api_key
|
| 100 |
+
],
|
| 101 |
+
outputs=[iti["output_image"], iti["status"]]
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
# Text to Video
|
| 105 |
+
ttv = tabs["text_to_video"]
|
| 106 |
+
ttv["generate_btn"].click(
|
| 107 |
+
fn=Handlers.generate_video,
|
| 108 |
+
inputs=[
|
| 109 |
+
ttv["prompt"],
|
| 110 |
+
ttv["duration"],
|
| 111 |
+
ttv["style"],
|
| 112 |
+
api_key
|
| 113 |
+
],
|
| 114 |
+
outputs=[ttv["output_video"], ttv["status"]]
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# Image to Video
|
| 118 |
+
itv = tabs["image_to_video"]
|
| 119 |
+
itv["animate_btn"].click(
|
| 120 |
+
fn=Handlers.animate_image,
|
| 121 |
+
inputs=[
|
| 122 |
+
itv["input_image"],
|
| 123 |
+
itv["motion_prompt"],
|
| 124 |
+
itv["duration"],
|
| 125 |
+
api_key
|
| 126 |
+
],
|
| 127 |
+
outputs=[itv["output_video"], itv["status"]]
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
return demo
|
| 131 |
+
|
| 132 |
|
| 133 |
+
demo = create_demo()
|
| 134 |
|
| 135 |
+
if __name__ == "__main__":
|
| 136 |
+
demo.launch()
|