Adityadn commited on
Commit
d8237e6
·
verified ·
1 Parent(s): 6a95ad2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+
4
+ # Ambil daftar format gambar yang didukung oleh Pillow
5
+ supported_formats = sorted(Image.SAVE.keys())
6
+
7
+ def convert_image(image, target_format):
8
+ try:
9
+ # Buka file gambar
10
+ img = Image.open(image)
11
+
12
+ # Nama file keluaran
13
+ output_file = f"converted_image.{target_format.lower()}"
14
+
15
+ # Simpan gambar dalam format yang dipilih
16
+ img.save(output_file, format=target_format.upper())
17
+
18
+ return output_file
19
+ except Exception as e:
20
+ return f"Error: {e}"
21
+
22
+ # Antarmuka Gradio
23
+ interface = gr.Interface(
24
+ fn=convert_image,
25
+ inputs=[
26
+ gr.Image(label="Upload Image", type="file"),
27
+ gr.Dropdown(label="Select Target Format", choices=supported_formats)
28
+ ],
29
+ outputs=gr.File(label="Converted Image"),
30
+ title="Universal Image Format Converter",
31
+ description="Upload an image and select any target format for conversion. Supports all formats recognized by Pillow."
32
+ )
33
+
34
+ # Jalankan aplikasi
35
+ if __name__ == "__main__":
36
+ interface.launch()