import gradio as gr from PIL import Image from PIL import ImageSequence import numpy as np from apng import APNG import os import subprocess def convert_audio(audio_file, output_format, change_bitrate, bitrate): if audio_file is None: return "Error: No audio file uploaded." # Get the base name of the input file base_name = os.path.splitext(os.path.basename(audio_file))[0] # Convert the audio file to the selected format output_audio_file = f'{base_name}.{output_format}' # Create the ffmpeg command command = ['ffmpeg', '-y', '-i', audio_file] if output_format == "m4r": command.extend(['-f', 'mp4']) if change_bitrate: command.extend(['-b:a', f'{bitrate}k']) command.append(output_audio_file) # Run the command try: subprocess.run(command, check=True) except subprocess.CalledProcessError as e: return f"Error in conversion: {str(e)}" return output_audio_file def convert_image(input_image, output_format, change_resolution, width, height): if input_image is None: return "Error: No image file uploaded." base_name = os.path.splitext(os.path.basename(input_image))[0] out_file = f'{base_name}.{output_format}' command = ['ffmpeg', '-y', '-i', input_image, '-vframes', '1'] if change_resolution: command.extend(['-vf', f'scale={width}:{height}']) command.append(out_file) try: subprocess.run(command, check=True) except subprocess.CalledProcessError as e: return f"Error in conversion: {str(e)}" return out_file def main(): # Gradio Interface with gr.Blocks() as app: gr.Markdown( """ #
Ilaria Converter 💖
File conversion Software by Ilaria, support her on [Ko-Fi!](https://ko-fi.com/ilariaowo) Need help with AI? [Join AI Hub!](https://discord.gg/aihub) """ ) with gr.Tab('Audio Conversion'): with gr.Row(): audio_input = gr.Audio(type='filepath', label="Upload Audio File") with gr.Column(): audio_output_format = gr.Dropdown(["wav", "flac", "ogg", "mp3", "aac", "m4a", "m4r"], label="Audio Output Format", info="Choose the desired output format for the audio file.") change_bitrate = gr.Checkbox(label="Change Bitrate?") audio_bitrate = gr.Dropdown(["128", "256", "320"], label="Audio Bitrate", info="Choose the bitrate for the audio file.") with gr.Column(): convert_audio_butt = gr.Button(value='Convert Audio', variant='primary') with gr.Column(): audio_output = gr.File(label="Download Converted Audio") convert_audio_butt.click(fn=convert_audio, inputs=[audio_input, audio_output_format, change_bitrate, audio_bitrate], outputs=audio_output) with gr.Tab('Image Conversion'): with gr.Row(): image_input = gr.Image(type='filepath', image_mode='RGBA', label="Upload Image") with gr.Column(): image_output_format = gr.Dropdown(["png", "jpg", "tiff", "bmp", "webp", "gif", "apng"], label="Image Output Format", info="Choose the desired output format for the image file.") change_resolution = gr.Checkbox(label="Change Resolution?") image_width = gr.Number(label="Image Width", value=1024, visible=False) image_height = gr.Number(label="Image Height", value=768, visible=False) with gr.Column(): convert_image_butt = gr.Button(value='Convert Image', variant='primary') with gr.Column(): image_output = gr.File(label="Download Converted Image") convert_image_butt.click(fn=convert_image, inputs=[image_input, image_output_format, change_resolution, image_width, image_height], outputs=image_output) with gr.Tab(""): gr.Markdown(''' ![note](https://huggingface.co/spaces/Blane187/Ilaria_RVC_mod/resolve/main/blane187'snote.png) ''') app.queue(max_size=1022).launch(share=False) # Create the Gradio interface main()