Adityadn commited on
Commit
4b959ff
·
verified ·
1 Parent(s): 009280d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -3,9 +3,10 @@ from PIL import Image
3
  import os
4
  import ffmpeg
5
 
 
6
  gr.themes.Soft()
7
 
8
- # Ambil daftar format gambar yang didukung oleh Pillow
9
  supported_formats = sorted(Image.SAVE.keys()) or ['BLP', 'BMP', 'BUFR', 'DDS', 'DIB', 'EPS',
10
  'GIF', 'GRIB', 'HDF5', 'ICNS', 'ICO', 'IM',
11
  'JPEG', 'JPEG2000', 'MPO', 'MSP', 'PALM', 'PCX',
@@ -19,26 +20,33 @@ def convert_image_ffmpeg(image, target_format):
19
  # Nama file keluaran dengan awalan yang diinginkan
20
  output_file = f"flowly_ai_image_converter_{base_name}.{target_format.lower()}"
21
 
22
- # Perintah FFmpeg untuk mengonversi gambar
23
- ffmpeg.input(image).output(output_file, format=target_format).overwrite_output().run() # Supaya tidak menampilkan output FFmpeg di konsol
 
 
 
 
 
 
24
 
25
  return output_file
26
  except Exception as e:
27
  return f"Error: {e}"
28
 
29
- # Antarmuka Gradio dengan tema kustom untuk menyembunyikan footer
30
  interface = gr.Interface(
31
  fn=convert_image_ffmpeg,
32
  inputs=[
33
- gr.Image(label="Upload Image", type="filepath", height=512), # Atur tinggi gambar input
34
- gr.Dropdown(label="Select Target Format", choices=supported_formats)
35
  ],
36
- outputs=gr.File(label="Converted Image"),
37
  title="Image Format Converter",
38
- description="Upload an image and select any target format for conversion using FFmpeg. Supports popular image formats.",
39
- css="footer {visibility: hidden}"
40
  )
41
 
42
  # Jalankan aplikasi
43
  if __name__ == "__main__":
44
- interface.launch()
 
 
3
  import os
4
  import ffmpeg
5
 
6
+ # Atur tema Gradio
7
  gr.themes.Soft()
8
 
9
+ # Format gambar yang didukung
10
  supported_formats = sorted(Image.SAVE.keys()) or ['BLP', 'BMP', 'BUFR', 'DDS', 'DIB', 'EPS',
11
  'GIF', 'GRIB', 'HDF5', 'ICNS', 'ICO', 'IM',
12
  'JPEG', 'JPEG2000', 'MPO', 'MSP', 'PALM', 'PCX',
 
20
  # Nama file keluaran dengan awalan yang diinginkan
21
  output_file = f"flowly_ai_image_converter_{base_name}.{target_format.lower()}"
22
 
23
+ # Gunakan ffmpeg untuk konversi
24
+ (
25
+ ffmpeg
26
+ .input(image)
27
+ .output(output_file, format=target_format)
28
+ .overwrite_output()
29
+ .run(capture_stdout=True, capture_stderr=True)
30
+ )
31
 
32
  return output_file
33
  except Exception as e:
34
  return f"Error: {e}"
35
 
36
+ # Antarmuka Gradio
37
  interface = gr.Interface(
38
  fn=convert_image_ffmpeg,
39
  inputs=[
40
+ gr.Image(label="Upload Image", type="filepath", height=512), # Input gambar
41
+ gr.Dropdown(label="Select Target Format", choices=supported_formats) # Pilih format
42
  ],
43
+ outputs=gr.File(label="Converted Image"), # Output file hasil
44
  title="Image Format Converter",
45
+ description="Upload an image and select any target format for conversion using FFmpeg.",
46
+ css="footer {visibility: hidden}" # Sembunyikan footer
47
  )
48
 
49
  # Jalankan aplikasi
50
  if __name__ == "__main__":
51
+ interface.launch()
52
+