FILMITO commited on
Commit
280cba5
Β·
verified Β·
1 Parent(s): 74e496a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -4,6 +4,7 @@ import numpy as np
4
  import tempfile
5
  import librosa
6
  import soundfile as sf
 
7
 
8
  class SimpleMP3Humanizer:
9
  def __init__(self):
@@ -47,12 +48,7 @@ class SimpleMP3Humanizer:
47
  def create_simple_music(self, midi, y, sr, duration, style, intensity):
48
  """Create basic musical structure"""
49
  # Create beats
50
- num_beats = int(duration * 2) # 2 beats per second
51
- if num_beats < 8:
52
- num_beats = 8
53
- if num_beats > 32:
54
- num_beats = 32
55
-
56
  beat_times = np.linspace(0, duration, num_beats)
57
 
58
  instruments = midi.instruments
@@ -129,12 +125,12 @@ def convert_mp3(input_mp3, style, intensity):
129
  output_path = tempfile.mktemp(suffix='_humanized.mp3')
130
  sf.write(output_path, audio_data, sr)
131
 
132
- return output_path, "βœ… Conversion successful! Download your humanized song below."
133
 
134
  except Exception as e:
135
  return None, f"❌ Error: {str(e)}"
136
 
137
- # Clean and simple interface
138
  with gr.Blocks(theme=gr.themes.Soft(), title="MP3 Humanizer") as demo:
139
  gr.Markdown("""
140
  # 🎡 MP3 Humanizer
@@ -159,7 +155,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="MP3 Humanizer") as demo:
159
 
160
  intensity = gr.Slider(
161
  0.1, 1.0, value=0.7,
162
- label="Human Feel"
163
  )
164
 
165
  convert_btn = gr.Button(
@@ -176,36 +172,33 @@ with gr.Blocks(theme=gr.themes.Soft(), title="MP3 Humanizer") as demo:
176
  interactive=False
177
  )
178
 
179
- download_btn = gr.DownloadButton(
180
- "πŸ“₯ Download MP3",
181
- visible=False,
182
- size="lg"
183
- )
184
-
185
  status = gr.Textbox(
186
  label="Status",
187
  interactive=False
188
  )
189
 
190
- # Simple conversion process
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  def process_conversion(input_mp3, style, intensity):
192
  output_path, message = convert_mp3(input_mp3, style, intensity)
193
- if output_path:
194
- return output_path, output_path, gr.DownloadButton(visible=True), message
195
- else:
196
- return None, None, gr.DownloadButton(visible=False), message
197
 
198
  convert_btn.click(
199
  fn=process_conversion,
200
  inputs=[input_audio, style, intensity],
201
- outputs=[output_audio, download_btn, download_btn, status]
202
- )
203
-
204
- # Update download button when audio is ready
205
- output_audio.change(
206
- lambda x: gr.DownloadButton(visible=(x is not None)),
207
- inputs=[output_audio],
208
- outputs=[download_btn]
209
  )
210
 
211
  if __name__ == "__main__":
 
4
  import tempfile
5
  import librosa
6
  import soundfile as sf
7
+ import os
8
 
9
  class SimpleMP3Humanizer:
10
  def __init__(self):
 
48
  def create_simple_music(self, midi, y, sr, duration, style, intensity):
49
  """Create basic musical structure"""
50
  # Create beats
51
+ num_beats = max(8, min(32, int(duration * 2))) # 2 beats per second
 
 
 
 
 
52
  beat_times = np.linspace(0, duration, num_beats)
53
 
54
  instruments = midi.instruments
 
125
  output_path = tempfile.mktemp(suffix='_humanized.mp3')
126
  sf.write(output_path, audio_data, sr)
127
 
128
+ return output_path, "βœ… Conversion successful! Your humanized song is ready below."
129
 
130
  except Exception as e:
131
  return None, f"❌ Error: {str(e)}"
132
 
133
+ # Simple and compatible interface
134
  with gr.Blocks(theme=gr.themes.Soft(), title="MP3 Humanizer") as demo:
135
  gr.Markdown("""
136
  # 🎡 MP3 Humanizer
 
155
 
156
  intensity = gr.Slider(
157
  0.1, 1.0, value=0.7,
158
+ label="Human Feel Intensity"
159
  )
160
 
161
  convert_btn = gr.Button(
 
172
  interactive=False
173
  )
174
 
 
 
 
 
 
 
175
  status = gr.Textbox(
176
  label="Status",
177
  interactive=False
178
  )
179
 
180
+ # Simple instructions
181
+ with gr.Accordion("πŸ“– How to Use", open=True):
182
+ gr.Markdown("""
183
+ 1. **Upload** your AI-generated MP3 file
184
+ 2. **Choose** your preferred music style
185
+ 3. **Adjust** the human feel slider
186
+ 4. **Click Convert** and wait a few seconds
187
+ 5. **Play the preview** to hear your humanized song
188
+ 6. **Click the download icon** in the audio player to save your MP3
189
+
190
+ That's it! You'll get a complete MP3 file with drums, bass, melody, and human-sounding timing.
191
+ """)
192
+
193
+ # Conversion process
194
  def process_conversion(input_mp3, style, intensity):
195
  output_path, message = convert_mp3(input_mp3, style, intensity)
196
+ return output_path, message
 
 
 
197
 
198
  convert_btn.click(
199
  fn=process_conversion,
200
  inputs=[input_audio, style, intensity],
201
+ outputs=[output_audio, status]
 
 
 
 
 
 
 
202
  )
203
 
204
  if __name__ == "__main__":