bartman081523 commited on
Commit
a5e228d
1 Parent(s): 1fc17fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -16
app.py CHANGED
@@ -59,32 +59,58 @@ def convert_to_wav(data, sample_rate):
59
 
60
  return temp_file
61
 
62
- def download_wav():
63
- data, sample_rate = generate_vinyl_sound(0.001, 300, 5000, 10, 10)
64
  temp_file = convert_to_wav(data, sample_rate)
65
  shutil.move(temp_file, "download.wav")
66
  return "download.wav"
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  iface = gr.Interface(
69
- generate_vinyl_sound,
70
- [
71
- gr.inputs.Slider(minimum=0, maximum=1, default=0.001, step=0.001, label="Noise Ratio"),
72
- gr.inputs.Slider(minimum=20, maximum=20000, default=300, step=10, label="Lowcut Frequency (Hz)"),
73
- gr.inputs.Slider(minimum=20, maximum=20000, default=5000, step=10, label="Highcut Frequency (Hz)"),
74
- gr.inputs.Slider(minimum=1, maximum=60, default=10, step=1, label="Duration (seconds)"),
75
- gr.inputs.Slider(minimum=1, maximum=100, default=10, step=1, label="Pop Rate (pops per second)")
76
- ],
77
- [
78
- gr.outputs.Audio(label="Generated Vinyl Sound", type="numpy"),
79
- gr.outputs.Button(label="Download Vinyl Sound", type="auto")
80
- ],
81
  title="Vinyl Sound Generator",
82
  description="Generate a synthetic vinyl sound using pink noise, rumble, hiss, and pops. Adjust the noise ratio, bandpass frequencies, duration, and pop rate to modify the sound.",
83
  examples=[
84
  [0.001, 300, 5000, 10, 10],
85
  [0.002, 500, 4000, 15, 20],
86
  [0.005, 200, 6000, 20, 30]
87
- ]
 
 
 
 
 
88
  )
89
 
90
- iface.launch(download_button=download_wav)
 
59
 
60
  return temp_file
61
 
62
+ def download_wav(noise_ratio, lowcut, highcut, duration, pop_rate):
63
+ data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
64
  temp_file = convert_to_wav(data, sample_rate)
65
  shutil.move(temp_file, "download.wav")
66
  return "download.wav"
67
 
68
+ # HTML template for the custom UI
69
+ html_template = """
70
+ <div style="padding: 20px;">
71
+ <h2>Vinyl Sound Generator</h2>
72
+ <p>Adjust the parameters to generate a synthetic vinyl sound:</p>
73
+ <form method="POST" action="/" target="_blank">
74
+ <label for="noise_ratio">Noise Ratio:</label>
75
+ <input type="range" id="noise_ratio" name="noise_ratio" min="0" max="1" step="0.001" value="0.001">
76
+ <br><br>
77
+ <label for="lowcut">Lowcut Frequency (Hz):</label>
78
+ <input type="range" id="lowcut" name="lowcut" min="20" max="20000" step="10" value="300">
79
+ <br><br>
80
+ <label for="highcut">Highcut Frequency (Hz):</label>
81
+ <input type="range" id="highcut" name="highcut" min="20" max="20000" step="10" value="5000">
82
+ <br><br>
83
+ <label for="duration">Duration (seconds):</label>
84
+ <input type="range" id="duration" name="duration" min="1" max="60" step="1" value="10">
85
+ <br><br>
86
+ <label for="pop_rate">Pop Rate (pops per second):</label>
87
+ <input type="range" id="pop_rate" name="pop_rate" min="1" max="100" step="1" value="10">
88
+ <br><br>
89
+ <input type="submit" value="Generate Vinyl Sound">
90
+ </form>
91
+ </div>
92
+ """
93
+
94
+ def vinyl_sound_app(noise_ratio, lowcut, highcut, duration, pop_rate):
95
+ data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
96
+ return data
97
+
98
  iface = gr.Interface(
99
+ fn=vinyl_sound_app,
100
+ inputs=["slider", "slider", "slider", "slider", "slider"],
101
+ outputs="audio",
 
 
 
 
 
 
 
 
 
102
  title="Vinyl Sound Generator",
103
  description="Generate a synthetic vinyl sound using pink noise, rumble, hiss, and pops. Adjust the noise ratio, bandpass frequencies, duration, and pop rate to modify the sound.",
104
  examples=[
105
  [0.001, 300, 5000, 10, 10],
106
  [0.002, 500, 4000, 15, 20],
107
  [0.005, 200, 6000, 20, 30]
108
+ ],
109
+ allow_flagging=False,
110
+ layout="horizontal",
111
+ capture_session=True,
112
+ live=False,
113
+ template=html_template
114
  )
115
 
116
+ iface.launch(inbrowser=True)