import os import gradio as gr from gradio_client import Client, handle_file from themes import IndonesiaTheme # Impor tema custom dari themes.py from PIL import Image # Siapkan URL dan header untuk permintaan API url_api = os.environ['url_api'] # Fungsi untuk menyimpan gambar sementara ke file def save_temp_image(image_array, filename): image = Image.fromarray(image_array.astype('uint8')) image.save(filename) # Fungsi untuk memanggil API Virtual Try-On def virtual_tryon(person_img, garment_img, seed, randomize_seed): client = Client(url_api) # Simpan gambar sementara person_img_path = "temp_person_img.png" garment_img_path = "temp_garment_img.png" save_temp_image(person_img, person_img_path) save_temp_image(garment_img, garment_img_path) result = client.predict( person_img=handle_file(person_img_path), garment_img=handle_file(garment_img_path), seed=seed, randomize_seed=randomize_seed, api_name="/tryon" ) # Hapus file sementara setelah selesai os.remove(person_img_path) os.remove(garment_img_path) return result[0], result[1], result[2] # Fungsi untuk memuat deskripsi dari file def load_description(fp): with open(fp, 'r', encoding='utf-8') as f: content = f.read() return content # Path untuk contoh gambar example_path = os.path.join(os.path.dirname(__file__), 'assets') # Daftar gambar pakaian contoh garm_list = os.listdir(os.path.join(example_path, "cloth")) garm_list_path = [os.path.join(example_path, "cloth", garm) for garm in garm_list] # Daftar gambar orang contoh human_list = os.listdir(os.path.join(example_path, "human")) human_list_path = [os.path.join(example_path, "human", human) for human in human_list] # CSS untuk styling antarmuka css = """ #col-left, #col-mid, #col-right { margin: 0 auto; max-width: 400px; padding: 10px; border-radius: 15px; background-color: #f9f9f9; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } #banner { width: 100%; text-align: center; margin-bottom: 20px; } #run-button { background-color: #ff4b5c; color: white; font-weight: bold; padding: 10px; border-radius: 10px; cursor: pointer; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); } #footer { text-align: center; margin-top: 20px; color: silver; } """ # Membuat antarmuka Gradio dengan tema IndonesiaTheme with gr.Blocks(css=css, theme=IndonesiaTheme()) as app: # Tambahkan banner gr.HTML("""