Peter Shi commited on
Commit
42e2df6
Β·
1 Parent(s): 832604f

Revert to simple clean UI

Browse files
Files changed (1) hide show
  1. app.py +29 -132
app.py CHANGED
@@ -4,7 +4,6 @@ import torch
4
  import torchaudio
5
  import tempfile
6
  import warnings
7
- import os
8
  warnings.filterwarnings("ignore")
9
 
10
  from sam_audio import SAMAudio, SAMAudioProcessor
@@ -49,150 +48,48 @@ def separate_audio(audio_path, video_path, text_prompt):
49
  target_path = save_audio(result.target[0].unsqueeze(0).cpu(), sample_rate)
50
  residual_path = save_audio(result.residual[0].unsqueeze(0).cpu(), sample_rate)
51
 
52
- return target_path, residual_path, f"βœ… Successfully isolated **'{text_prompt}'**"
53
 
54
  except Exception as e:
55
  import traceback
56
  traceback.print_exc()
57
  return None, None, f"❌ Error: {str(e)}"
58
 
59
- # Custom CSS
60
- custom_css = """
61
- .gradio-container {
62
- background: #0d0d0d !important;
63
- max-width: 1400px !important;
64
- }
65
-
66
- .gradio-container *, .gradio-container p, .gradio-container span,
67
- .gradio-container h1, .gradio-container h2, .gradio-container h3,
68
- .gradio-container label, .gradio-container .markdown-text {
69
- color: #ffffff !important;
70
- }
71
-
72
- input, textarea {
73
- background: #1a1a1a !important;
74
- border: 1px solid #444 !important;
75
- color: #ffffff !important;
76
- }
77
-
78
- input::placeholder, textarea::placeholder {
79
- color: #888 !important;
80
- }
81
-
82
- .primary-btn {
83
- background: linear-gradient(135deg, #e91e8c, #9c27b0) !important;
84
- border: none !important;
85
- border-radius: 24px !important;
86
- color: #ffffff !important;
87
- font-weight: 600 !important;
88
- }
89
-
90
- .example-btn {
91
- background: #2a2a2a !important;
92
- border: 1px solid #444 !important;
93
- color: #ffffff !important;
94
- border-radius: 8px !important;
95
- }
96
-
97
- .example-btn:hover {
98
- background: #3a3a3a !important;
99
- border-color: #e91e8c !important;
100
- }
101
-
102
- hr {
103
- border-color: #333 !important;
104
- }
105
- """
106
-
107
- # Build Gradio Interface
108
- with gr.Blocks(
109
- title="SAM-Audio - Isolate Sounds",
110
- theme=gr.themes.Default(
111
- primary_hue="pink",
112
- secondary_hue="purple",
113
- neutral_hue="gray",
114
- ),
115
- css=custom_css
116
- ) as demo:
117
 
118
  with gr.Row():
119
- # Sidebar
120
- with gr.Column(scale=1, min_width=260):
121
- gr.Markdown("# 🎡 Isolate Sounds")
122
- gr.Markdown("Extract and isolate any sound from audio or video using AI.")
123
-
124
- gr.Markdown("---")
125
- gr.Markdown("### How it works")
126
- gr.Markdown("**1.** Add audio or video")
127
- gr.Markdown("**2.** Describe the sound")
128
- gr.Markdown("**3.** Get separated tracks")
129
 
130
- gr.Markdown("---")
131
- gr.Markdown("**Model:** SAM-Audio Small")
132
-
133
- # Main content area
134
- with gr.Column(scale=4):
135
- gr.Markdown("## πŸ“€ Upload Audio or Video")
136
-
137
- with gr.Tabs():
138
- with gr.TabItem("οΏ½ Audio"):
139
- input_audio = gr.Audio(
140
- label="Upload audio file (MP3, WAV, FLAC, etc.)",
141
- type="filepath"
142
- )
143
-
144
- with gr.TabItem("🎬 Video"):
145
- input_video = gr.Video(
146
- label="Upload video file (MP4, MKV, AVI, etc.)"
147
- )
148
-
149
- gr.Markdown("## πŸ’¬ Describe the Sound")
150
  text_prompt = gr.Textbox(
151
- label="",
152
  placeholder="e.g., 'A man speaking', 'Piano melody', 'Dog barking'",
153
- lines=1
154
- )
155
-
156
- run_btn = gr.Button(
157
- "🎯 Isolate Sound",
158
- variant="primary",
159
- size="lg",
160
- elem_classes=["primary-btn"]
161
- )
162
-
163
- status_output = gr.Markdown(
164
- value="Upload a file and describe what sound you want to isolate."
165
  )
166
 
167
- gr.Markdown("---")
168
- gr.Markdown("## 🎧 Results")
169
-
170
- with gr.Row():
171
- with gr.Column():
172
- gr.Markdown("**🎯 Isolated Sound (Target)**")
173
- output_target = gr.Audio(label="", show_label=False)
174
-
175
- with gr.Column():
176
- gr.Markdown("**πŸ”‡ Background (Residual)**")
177
- output_residual = gr.Audio(label="", show_label=False)
178
-
179
- gr.Markdown("---")
180
- gr.Markdown("## πŸ’‘ Example Prompts")
181
-
182
- with gr.Row():
183
- btn1 = gr.Button("A man speaking", elem_classes=["example-btn"])
184
- btn2 = gr.Button("A woman singing", elem_classes=["example-btn"])
185
- btn3 = gr.Button("Piano", elem_classes=["example-btn"])
186
- btn4 = gr.Button("Drums", elem_classes=["example-btn"])
187
- btn5 = gr.Button("Guitar", elem_classes=["example-btn"])
188
- btn6 = gr.Button("Dog barking", elem_classes=["example-btn"])
189
-
190
- btn1.click(fn=lambda: "A man speaking", outputs=[text_prompt])
191
- btn2.click(fn=lambda: "A woman singing", outputs=[text_prompt])
192
- btn3.click(fn=lambda: "Piano", outputs=[text_prompt])
193
- btn4.click(fn=lambda: "Drums", outputs=[text_prompt])
194
- btn5.click(fn=lambda: "Guitar", outputs=[text_prompt])
195
- btn6.click(fn=lambda: "Dog barking", outputs=[text_prompt])
196
 
197
  run_btn.click(
198
  fn=separate_audio,
 
4
  import torchaudio
5
  import tempfile
6
  import warnings
 
7
  warnings.filterwarnings("ignore")
8
 
9
  from sam_audio import SAMAudio, SAMAudioProcessor
 
48
  target_path = save_audio(result.target[0].unsqueeze(0).cpu(), sample_rate)
49
  residual_path = save_audio(result.residual[0].unsqueeze(0).cpu(), sample_rate)
50
 
51
+ return target_path, residual_path, f"βœ… Successfully isolated '{text_prompt}'"
52
 
53
  except Exception as e:
54
  import traceback
55
  traceback.print_exc()
56
  return None, None, f"❌ Error: {str(e)}"
57
 
58
+ # Build Gradio Interface - Simple and clean
59
+ with gr.Blocks(title="SAM-Audio Demo") as demo:
60
+ gr.Markdown(
61
+ """
62
+ # 🎡 SAM-Audio: Segment Anything for Audio
63
+
64
+ Isolate specific sounds from an audio or video file using natural language prompts.
65
+
66
+ **Model:** [facebook/sam-audio-small](https://huggingface.co/facebook/sam-audio-small)
67
+ """
68
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  with gr.Row():
71
+ with gr.Column():
72
+ gr.Markdown("### Upload Audio or Video")
73
+ input_audio = gr.Audio(label="Audio File", type="filepath")
74
+ input_video = gr.Video(label="Video File (MP4)")
 
 
 
 
 
 
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  text_prompt = gr.Textbox(
77
+ label="Text Prompt",
78
  placeholder="e.g., 'A man speaking', 'Piano melody', 'Dog barking'",
79
+ info="Describe the sound you want to isolate."
 
 
 
 
 
 
 
 
 
 
 
80
  )
81
 
82
+ run_btn = gr.Button("🎯 Isolate Sound", variant="primary")
83
+ status_output = gr.Markdown(value="")
84
+
85
+ with gr.Column():
86
+ gr.Markdown("### Results")
87
+ output_target = gr.Audio(label="Isolated Sound (Target)")
88
+ output_residual = gr.Audio(label="Background (Residual)")
89
+
90
+ gr.Markdown("---")
91
+ gr.Markdown("### Example Prompts")
92
+ gr.Markdown("- A man speaking\n- A woman singing\n- Piano\n- Drums\n- Guitar\n- Dog barking\n- Car engine")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  run_btn.click(
95
  fn=separate_audio,