Blane187 commited on
Commit
a0fae27
·
verified ·
1 Parent(s): 814314c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -43
app.py CHANGED
@@ -6,46 +6,11 @@ from apng import APNG
6
  import os
7
  import subprocess
8
 
9
- def main():
10
- # Gradio Interface
11
- with gr.Blocks() as app:
12
- gr.Markdown(
13
- """
14
- # <div align="center"> Ilaria Converter 💖 </div>
15
- File conversion Software by Ilaria, support me on [Ko-Fi!](https://ko-fi.com/ilariaowo)
16
-
17
- Need help with AI? [Join AI Hub!](https://discord.gg/aihub)
18
- """
19
- )
20
-
21
- with gr.Tab('Audio Conversion'):
22
- with gr.Row():
23
- audio_input = gr.Audio(type='filepath')
24
- with gr.Column():
25
- audio_output_format = gr.Dropdown(["wav", "flac", "ogg", "mp3", "aac", "m4a", "m4r"], label="Audio Output Format")
26
- change_bitrate = gr.Checkbox(label="Change Bitrate?")
27
- audio_bitrate = gr.Dropdown(["128", "256", "320"], label="Audio Bitrate")
28
- convert_audio_butt = gr.Button(value='Convert Audio', variant='primary')
29
- audio_output = gr.Audio(type='filepath', label="Converted Audio")
30
-
31
- convert_audio_butt.click(fn=convert_audio, inputs=[audio_input, audio_output_format, change_bitrate, audio_bitrate], outputs=audio_output)
32
-
33
- with gr.Tab('Image Conversion'):
34
- with gr.Row():
35
- image_input = gr.Image(type='filepath', image_mode='RGBA')
36
- with gr.Column():
37
- image_output_format = gr.Dropdown(["png", "jpg", "tiff", "bmp", "webp", "gif", "apng"], label="Image Output Format")
38
- change_resolution = gr.Checkbox(label="Change Resolution?")
39
- image_width = gr.Number(label="Image Width")
40
- image_height = gr.Number(label="Image Height")
41
- convert_image_butt = gr.Button(value='Convert Image', variant='primary')
42
- image_output = gr.Image(type='filepath', label="Converted Image")
43
-
44
- convert_image_butt.click(fn=convert_image, inputs=[image_input, image_output_format, change_resolution, image_width, image_height], outputs=image_output)
45
-
46
- app.queue(max_size=1022).launch(share=False)
47
 
48
  def convert_audio(audio_file, output_format, change_bitrate, bitrate):
 
 
 
49
  # Get the base name of the input file
50
  base_name = os.path.splitext(os.path.basename(audio_file))[0]
51
 
@@ -61,11 +26,17 @@ def convert_audio(audio_file, output_format, change_bitrate, bitrate):
61
  command.append(output_audio_file)
62
 
63
  # Run the command
64
- subprocess.run(command, check=True)
 
 
 
65
 
66
  return output_audio_file
67
 
68
  def convert_image(input_image, output_format, change_resolution, width, height):
 
 
 
69
  base_name = os.path.splitext(os.path.basename(input_image))[0]
70
 
71
  out_file = f'{base_name}.{output_format}'
@@ -77,11 +48,56 @@ def convert_image(input_image, output_format, change_resolution, width, height):
77
 
78
  command.append(out_file)
79
 
80
- subprocess.run(command, check=True)
81
-
82
- print(f'Converted {input_image} to {out_file}')
 
83
 
84
  return out_file
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  # Create the Gradio interface
87
- main()
 
6
  import os
7
  import subprocess
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def convert_audio(audio_file, output_format, change_bitrate, bitrate):
11
+ if audio_file is None:
12
+ return "Error: No audio file uploaded."
13
+
14
  # Get the base name of the input file
15
  base_name = os.path.splitext(os.path.basename(audio_file))[0]
16
 
 
26
  command.append(output_audio_file)
27
 
28
  # Run the command
29
+ try:
30
+ subprocess.run(command, check=True)
31
+ except subprocess.CalledProcessError as e:
32
+ return f"Error in conversion: {str(e)}"
33
 
34
  return output_audio_file
35
 
36
  def convert_image(input_image, output_format, change_resolution, width, height):
37
+ if input_image is None:
38
+ return "Error: No image file uploaded."
39
+
40
  base_name = os.path.splitext(os.path.basename(input_image))[0]
41
 
42
  out_file = f'{base_name}.{output_format}'
 
48
 
49
  command.append(out_file)
50
 
51
+ try:
52
+ subprocess.run(command, check=True)
53
+ except subprocess.CalledProcessError as e:
54
+ return f"Error in conversion: {str(e)}"
55
 
56
  return out_file
57
 
58
+
59
+
60
+ def main():
61
+ # Gradio Interface
62
+ with gr.Blocks() as app:
63
+ gr.Markdown(
64
+ """
65
+ # <div align="center"> Ilaria Converter 💖 </div>
66
+ File conversion Software by Ilaria, support her on [Ko-Fi!](https://ko-fi.com/ilariaowo)
67
+
68
+ Need help with AI? [Join AI Hub!](https://discord.gg/aihub)
69
+ """
70
+ )
71
+
72
+ with gr.Tab('Audio Conversion'):
73
+ with gr.Row():
74
+ audio_input = gr.Audio(type='filepath', label="Upload Audio File")
75
+ with gr.Column():
76
+ 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.")
77
+ change_bitrate = gr.Checkbox(label="Change Bitrate?")
78
+ audio_bitrate = gr.Dropdown(["128", "256", "320"], label="Audio Bitrate", info="Choose the bitrate for the audio file.")
79
+ convert_audio_butt = gr.Button(value='Convert Audio', variant='primary')
80
+ audio_output = gr.File(label="Download Converted Audio")
81
+
82
+ convert_audio_butt.click(fn=convert_audio, inputs=[audio_input, audio_output_format, change_bitrate, audio_bitrate], outputs=audio_output)
83
+
84
+ with gr.Tab('Image Conversion'):
85
+ with gr.Row():
86
+ image_input = gr.Image(type='filepath', image_mode='RGBA', label="Upload Image")
87
+ with gr.Column():
88
+ 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.")
89
+ change_resolution = gr.Checkbox(label="Change Resolution?")
90
+ image_width = gr.Number(label="Image Width", value=1024, visible=False)
91
+ image_height = gr.Number(label="Image Height", value=768, visible=False)
92
+
93
+ convert_image_butt = gr.Button(value='Convert Image', variant='primary')
94
+ image_output = gr.File(label="Download Converted Image")
95
+
96
+ convert_image_butt.click(fn=convert_image, inputs=[image_input, image_output_format, change_resolution, image_width, image_height], outputs=image_output)
97
+ with gr.Tab(('')):
98
+ gr.Markdown("•••---•••")
99
+ app.queue(max_size=1022).launch(share=False)
100
+
101
+
102
  # Create the Gradio interface
103
+ main()