Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from moviepy.editor import AudioFileClip, ImageClip | |
| def convert_mp3_to_mp4(mp3_file, image_file): | |
| if mp3_file is None: | |
| return "Please upload an MP3 file." | |
| # Load the audio | |
| audio = AudioFileClip(mp3_file) | |
| # Use a default or uploaded image | |
| if image_file is None: | |
| image_file = "default.jpg" # Provide a default image path | |
| # Create a video clip from the image and set duration to match audio | |
| image = ImageClip(image_file, duration=audio.duration) | |
| image = image.set_audio(audio) | |
| # Set the final output size | |
| image = image.resize(height=720) # Resize for better compatibility | |
| # Output file | |
| output_path = "output.mp4" | |
| image.write_videofile(output_path, fps=1) | |
| return output_path | |
| iface = gr.Interface( | |
| fn=convert_mp3_to_mp4, | |
| inputs=[gr.File(label="Upload MP3"), gr.File(label="Upload Image (optional)")], | |
| outputs=gr.File(label="Download MP4"), | |
| title="MP3 to MP4 Converter", | |
| description="Convert an MP3 file to an MP4 video with a static image." | |
| ) | |
| iface.launch() | |