Adityadn's picture
Update app.py
34bcffb verified
raw
history blame
2.03 kB
import gradio as gr
from PIL import Image
import os
# Copyright 2025 Flowly AI. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# AI Project by Flowly AI, Created by: Aditya Dwi Nugraha
# Ambil daftar format gambar yang didukung oleh Pillow
supported_formats = sorted(Image.SAVE.keys())
def convert_image(image, target_format):
try:
# Buka file gambar
img = Image.open(image)
# Ambil nama file asli tanpa ekstensi
base_name = os.path.splitext(os.path.basename(image))[0]
# Nama file keluaran dengan awalan yang diinginkan
output_file = f"flowly_ai_image_converter_{base_name}.{target_format.lower()}"
# Simpan gambar dalam format yang dipilih
img.save(output_file, format=target_format.upper())
return output_file
except Exception as e:
return f"Error: {e}"
# Antarmuka Gradio
interface = gr.Interface(
fn=convert_image,
inputs=[
gr.Image(label="Upload Image", type="filepath", height=1000),
gr.Dropdown(label="Select Target Format", choices=supported_formats)
],
outputs=gr.File(label="Converted Image"),
title="Universal Image Format Converter",
description="""
Upload an image and select any target format for conversion. Supports all formats recognized by Pillow.
© 2025 Flowly AI. All rights reserved. Licensed under the Apache License 2.0. Created by Aditya Dwi Nugraha"""
)
# Jalankan aplikasi
if __name__ == "__main__":
interface.launch()