Spaces:
Running
Running
Update app.py
Browse files4 unmodified lines567891037 unmodified lines484950515253545556575859606155 unmodified lines117118119120121122123166 unmodified lines2902912922932942954 unmodified linesfrom pydub import AudioSegmentfrom pydub.silence import split_on_silenceimport redef clean_file_name(file_path):# Get the base file name and extension37 unmodified linesreturn duration_secondsdef process_audio(audio_file, seconds=0.05):keep_silence = int(seconds * 1000)output_audio_file = remove_silence(audio_file, minimum_silence=keep_silence)before = calculate_duration(audio_file)after = calculate_duration(output_audio_file)text = f"Old Duration: {before:.3f} seconds \nNew Duration: {after:.3f} seconds"return output_audio_file, output_audio_file, text# def ui():# theme = gr.themes.Soft(font=[gr.themes.GoogleFont("Source Sans Pro"), "Arial", "sans-serif"])# css = ".gradio-container {max-width: none !important;} .tab-content {padding: 20px;}"55 unmodified lines<p style="font-size:1.05em; color:#555; margin:0 0 10px;">Upload an MP3 or WAV file, and it will remove silent parts from it.</p><p style="font-size:0.9em; color:#777;">Install locally on your computer, enjoy unlimited runs with no waiting queue<a href="https://github.com/NeuralFalconYT/Remove-Silence-From-Audio" target="_blank" style="text-decoration:none;">166 unmodified lines@click.option("--debug", is_flag=True, default=False, help="Enable debug mode.")@click.option("--share", is_flag=True, default=False, help="Enable sharing of the interface.")def main(debug, share):demo=ui()demo.queue().launch(debug=debug, share=share)if __name__ == "__main__":4 unmodified lines5678910111237 unmodified lines505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811955 unmodified lines175176177178179180181182183166 unmodified lines3503513523533543553564 unmodified linesfrom pydub import AudioSegmentfrom pydub.silence import split_on_silenceimport reimport timedef clean_file_name(file_path):# Get the base file name and extension37 unmodified linesreturn duration_seconds# Some user uploads may trigger Hugging Face privacy policy checks, which can lead to account suspensionFILE_TIMESTAMPS = {}def track_file(file_path):FILE_TIMESTAMPS[file_path] = time.time()def cleanup_tracked_files(max_age_seconds=3600):now = time.time()to_delete = []for file_path, created_time in FILE_TIMESTAMPS.items():if now - created_time > max_age_seconds:if os.path.exists(file_path):try:os.remove(file_path)print(f"🗑️ Deleted: {file_path}")except Exception as e:print(f"⚠️ Error deleting {file_path}: {e}")to_delete.append(file_path)# Remove from trackingfor f in to_delete:FILE_TIMESTAMPS.pop(f, None)def start_cleanup_worker(interval=3600):def worker():while True:print("🔄 Cleaning tracked files...")cleanup_tracked_files()time.sleep(interval)import threadingthreading.Thread(target=worker, daemon=True).start()def process_audio(audio_file, seconds=0.05):if audio_file is None:return None, None, "No file uploaded"if not os.path.exists(audio_file):return None, None, "File not found"track_file(audio_file)keep_silence = int(seconds * 1000)output_audio_file = remove_silence(audio_file,minimum_silence=keep_silence)track_file(output_audio_file)before = calculate_duration(audio_file)after = calculate_duration(output_audio_file)text = f"Old Duration: {before:.3f} seconds \nNew Duration: {after:.3f} seconds"return output_audio_file, output_audio_file, text# def ui():# theme = gr.themes.Soft(font=[gr.themes.GoogleFont("Source Sans Pro"), "Arial", "sans-serif"])# css = ".gradio-container {max-width: none !important;} .tab-content {padding: 20px;}"55 unmodified lines<p style="font-size:1.05em; color:#555; margin:0 0 10px;">Upload an MP3 or WAV file, and it will remove silent parts from it.</p><p style="font-size:0.8em; color:#999;">⚠️ Please don’t upload copyrighted content — it can take this Space offline.</p><p style="font-size:0.9em; color:#777;">Install locally on your computer, enjoy unlimited runs with no waiting queue<a href="https://github.com/NeuralFalconYT/Remove-Silence-From-Audio" target="_blank" style="text-decoration:none;">166 unmodified lines@click.option("--debug", is_flag=True, default=False, help="Enable debug mode.")@click.option("--share", is_flag=True, default=False, help="Enable sharing of the interface.")def main(debug, share):start_cleanup_worker()demo=ui()demo.queue().launch(debug=debug, share=share)if __name__ == "__main__":
app.py+64-3