Spaces:
Runtime error
Runtime error
Peter Shi
commited on
Commit
Β·
3cc9650
1
Parent(s):
a11009d
Simplify UI - remove tabs, fix example buttons
Browse files
app.py
CHANGED
|
@@ -29,13 +29,11 @@ current_model_name = None
|
|
| 29 |
model = None
|
| 30 |
processor = None
|
| 31 |
|
| 32 |
-
def load_model(model_name
|
| 33 |
global current_model_name, model, processor
|
| 34 |
model_id = MODELS.get(model_name, MODELS[DEFAULT_MODEL])
|
| 35 |
if current_model_name == model_name and model is not None:
|
| 36 |
return
|
| 37 |
-
if progress:
|
| 38 |
-
progress(0.1, desc="Loading model...")
|
| 39 |
print(f"Loading {model_id}...")
|
| 40 |
model = SAMAudio.from_pretrained(model_id).to(device).eval()
|
| 41 |
processor = SAMAudioProcessor.from_pretrained(model_id)
|
|
@@ -83,16 +81,6 @@ def separate_audio(model_name, file_path, text_prompt, progress=gr.Progress()):
|
|
| 83 |
traceback.print_exc()
|
| 84 |
return None, None, f"β Error: {str(e)}"
|
| 85 |
|
| 86 |
-
def process_audio(model_name, audio_path, prompt, progress=gr.Progress()):
|
| 87 |
-
if not audio_path:
|
| 88 |
-
return None, None, "β Please upload an audio file."
|
| 89 |
-
return separate_audio(model_name, audio_path, prompt, progress)
|
| 90 |
-
|
| 91 |
-
def process_video(model_name, video_path, prompt, progress=gr.Progress()):
|
| 92 |
-
if not video_path:
|
| 93 |
-
return None, None, "β Please upload a video file."
|
| 94 |
-
return separate_audio(model_name, video_path, prompt, progress)
|
| 95 |
-
|
| 96 |
# Build Interface
|
| 97 |
with gr.Blocks(title="SAM-Audio Demo") as demo:
|
| 98 |
gr.Markdown(
|
|
@@ -110,12 +98,11 @@ with gr.Blocks(title="SAM-Audio Demo") as demo:
|
|
| 110 |
label="Model"
|
| 111 |
)
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
input_video = gr.Video(label="Upload Video")
|
| 119 |
|
| 120 |
text_prompt = gr.Textbox(
|
| 121 |
label="Text Prompt",
|
|
@@ -132,7 +119,7 @@ with gr.Blocks(title="SAM-Audio Demo") as demo:
|
|
| 132 |
|
| 133 |
gr.Markdown("---")
|
| 134 |
gr.Markdown("### π¬ Demo Examples")
|
| 135 |
-
gr.Markdown("Click to load example
|
| 136 |
|
| 137 |
with gr.Row():
|
| 138 |
if os.path.exists(EXAMPLE_FILE):
|
|
@@ -140,28 +127,30 @@ with gr.Blocks(title="SAM-Audio Demo") as demo:
|
|
| 140 |
example_btn2 = gr.Button("π€ Woman Speaking")
|
| 141 |
example_btn3 = gr.Button("π΅ Background Music")
|
| 142 |
|
| 143 |
-
# Main process button
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
run_btn.click(
|
| 145 |
-
fn=
|
| 146 |
inputs=[model_selector, input_audio, input_video, text_prompt],
|
| 147 |
outputs=[output_target, output_residual, status_output]
|
| 148 |
)
|
| 149 |
|
| 150 |
-
# Example buttons -
|
| 151 |
if os.path.exists(EXAMPLE_FILE):
|
| 152 |
example_btn1.click(
|
| 153 |
-
fn=lambda: (EXAMPLE_FILE, "A man speaking"
|
| 154 |
-
outputs=[input_video, text_prompt
|
| 155 |
)
|
| 156 |
-
|
| 157 |
example_btn2.click(
|
| 158 |
-
fn=lambda: (EXAMPLE_FILE, "A woman speaking"
|
| 159 |
-
outputs=[input_video, text_prompt
|
| 160 |
)
|
| 161 |
-
|
| 162 |
example_btn3.click(
|
| 163 |
-
fn=lambda: (EXAMPLE_FILE, "Background music"
|
| 164 |
-
outputs=[input_video, text_prompt
|
| 165 |
)
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
|
|
|
| 29 |
model = None
|
| 30 |
processor = None
|
| 31 |
|
| 32 |
+
def load_model(model_name):
|
| 33 |
global current_model_name, model, processor
|
| 34 |
model_id = MODELS.get(model_name, MODELS[DEFAULT_MODEL])
|
| 35 |
if current_model_name == model_name and model is not None:
|
| 36 |
return
|
|
|
|
|
|
|
| 37 |
print(f"Loading {model_id}...")
|
| 38 |
model = SAMAudio.from_pretrained(model_id).to(device).eval()
|
| 39 |
processor = SAMAudioProcessor.from_pretrained(model_id)
|
|
|
|
| 81 |
traceback.print_exc()
|
| 82 |
return None, None, f"β Error: {str(e)}"
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
# Build Interface
|
| 85 |
with gr.Blocks(title="SAM-Audio Demo") as demo:
|
| 86 |
gr.Markdown(
|
|
|
|
| 98 |
label="Model"
|
| 99 |
)
|
| 100 |
|
| 101 |
+
gr.Markdown("#### Upload Audio")
|
| 102 |
+
input_audio = gr.Audio(label="Audio File", type="filepath")
|
| 103 |
+
|
| 104 |
+
gr.Markdown("#### Or Upload Video")
|
| 105 |
+
input_video = gr.Video(label="Video File")
|
|
|
|
| 106 |
|
| 107 |
text_prompt = gr.Textbox(
|
| 108 |
label="Text Prompt",
|
|
|
|
| 119 |
|
| 120 |
gr.Markdown("---")
|
| 121 |
gr.Markdown("### π¬ Demo Examples")
|
| 122 |
+
gr.Markdown("Click to load example video and prompt:")
|
| 123 |
|
| 124 |
with gr.Row():
|
| 125 |
if os.path.exists(EXAMPLE_FILE):
|
|
|
|
| 127 |
example_btn2 = gr.Button("π€ Woman Speaking")
|
| 128 |
example_btn3 = gr.Button("π΅ Background Music")
|
| 129 |
|
| 130 |
+
# Main process button
|
| 131 |
+
def process(model_name, audio_path, video_path, prompt, progress=gr.Progress()):
|
| 132 |
+
file_path = video_path if video_path else audio_path
|
| 133 |
+
return separate_audio(model_name, file_path, prompt, progress)
|
| 134 |
+
|
| 135 |
run_btn.click(
|
| 136 |
+
fn=process,
|
| 137 |
inputs=[model_selector, input_audio, input_video, text_prompt],
|
| 138 |
outputs=[output_target, output_residual, status_output]
|
| 139 |
)
|
| 140 |
|
| 141 |
+
# Example buttons - just fill the prompt, user clicks button to process
|
| 142 |
if os.path.exists(EXAMPLE_FILE):
|
| 143 |
example_btn1.click(
|
| 144 |
+
fn=lambda: (EXAMPLE_FILE, "A man speaking"),
|
| 145 |
+
outputs=[input_video, text_prompt]
|
| 146 |
)
|
|
|
|
| 147 |
example_btn2.click(
|
| 148 |
+
fn=lambda: (EXAMPLE_FILE, "A woman speaking"),
|
| 149 |
+
outputs=[input_video, text_prompt]
|
| 150 |
)
|
|
|
|
| 151 |
example_btn3.click(
|
| 152 |
+
fn=lambda: (EXAMPLE_FILE, "Background music"),
|
| 153 |
+
outputs=[input_video, text_prompt]
|
| 154 |
)
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|