Spaces:
Running
Running
File size: 5,826 Bytes
ca2e55b 0fbce6b ca2e55b 0fbce6b ca2e55b eb9eb1a ca2e55b eb9eb1a ca2e55b 29ca338 ca2e55b 0fbce6b ca2e55b 0fbce6b ca2e55b 0fbce6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
import gradio as gr
import numpy as np
import random
from gradio_client import Client
import os
from themes import IndonesiaTheme # Impor tema custom dari themes.py
# Constants
MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 2048
DEFAULT_WIDTH = 1024
DEFAULT_HEIGHT = 1024
DEFAULT_INFERENCE_STEPS = 1
# Siapkan URL untuk permintaan API RT FLUX
url_api = os.environ['url_api']
client = Client(url_api)
# Inference function using RealtimeFlux API
def generate_image(prompt, seed=42, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, randomize_seed=False, num_inference_steps=1):
result = client.predict(
prompt=prompt,
seed=seed if not randomize_seed else random.randint(0, MAX_SEED),
width=width,
height=height,
randomize_seed=randomize_seed,
num_inference_steps=num_inference_steps,
api_name="/RealtimeFlux"
)
return result[0], result[1], result[2] # Image, Seed, Latency
# Enhance function using Enhance API
def enhance_image(prompt, seed, width, height):
result = client.predict(
param_0=prompt,
param_1=seed,
param_2=width,
param_3=height,
api_name="/enhance_image"
)
return result[0], result[1], result[2] # Image, Seed, Latency
# 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);
}
#col-right {
margin: 0 auto;
max-width: 800px;
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;
}
#whitey {
text-align: center;
margin-top: 10px;
color: white;
}
"""
# Membuat antarmuka Gradio dengan tema IndonesiaTheme
with gr.Blocks(css=css, theme=IndonesiaTheme()) as RealtimeFluxAPP:
# Tambahkan banner dan header
gr.HTML("""
<div style='text-align: center;'>
<h1>๐ Realtime FLUX Image Generator ๐</h1>
<p>Selamat datang! Buat gambar memukau secara realtime dengan FLUX Pipeline.</p>
<img src='https://i.ibb.co.com/M2Sd185/banner-rtf.jpg' alt='Banner' style='width: 100%; height: auto;'/>
</div>
""")
# Layout utama
with gr.Row():
with gr.Column(elem_id="col-left"):
gr.Markdown("### Deskripsi Gambar")
prompt = gr.Textbox(
label="Prompt",
placeholder="Deskripsikan gambar yang ingin Anda buat...",
lines=3,
show_label=False,
container=False,
)
generateBtn = gr.Button("๐ผ๏ธ Buat Gambar", elem_id="run-button")
enhanceBtn = gr.Button("๐ Tingkatkan Gambar", elem_id="run-button")
# Advanced Options
with gr.Accordion("Advanced Options"):
with gr.Row():
realtime = gr.Checkbox(label="Realtime Toggler", info="Gunakan lebih banyak GPU untuk realtime.")
latency = gr.Textbox(label="Latency")
with gr.Row():
seed = gr.Number(label="Seed", value=42)
randomize_seed = gr.Checkbox(label="Randomize Seed", value=False)
with gr.Row():
width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_WIDTH)
height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_HEIGHT)
num_inference_steps = gr.Slider(label="Inference Steps", minimum=1, maximum=4, step=1, value=DEFAULT_INFERENCE_STEPS)
# Output di sebelah kanan
with gr.Column(elem_id="col-right"):
result = gr.Image(label="Hasil Gambar", show_label=False, interactive=False)
# Example Gallery
gr.Markdown("### ๐ Inspirasi Gallery")
gr.Examples(elem_id="whitey",
examples=[
"A beautiful sunset over the rice fields in Bali",
"A traditional Indonesian fisherman sailing in a wooden boat",
"Mount Bromo erupting at dawn with the sky full of stars",
"A street food vendor selling nasi goreng in Jakarta",
"The majestic Komodo dragon walking through the forest",
"An Indonesian traditional dancer performing in a colorful costume",
"A futuristic cityscape of Jakarta with skyscrapers and advanced technology",
],
fn=generate_image,
inputs=[prompt],
outputs=[result, seed, latency],
cache_examples="lazy"
)
# Tombol untuk memulai proses pembuatan dan peningkatan gambar
generateBtn.click(
fn=generate_image,
inputs=[prompt, seed, width, height, randomize_seed, num_inference_steps],
outputs=[result, seed, latency],
show_progress="full",
)
enhanceBtn.click(
fn=enhance_image,
inputs=[prompt, seed, width, height],
outputs=[result, seed, latency],
show_progress="hidden",
queue=False,
concurrency_limit=None
)
# Tambahkan footer di bagian bawah
gr.HTML("""
<footer id="footer">
<p>Transfer Energi Semesta Digital ยฉ 2024 __drat. | ๐ฎ๐ฉ Untuk Indonesia Jaya!</p>
</footer>
""")
# Menjalankan aplikasi
if __name__ == "__main__":
RealtimeFluxAPP.launch(show_api=False, show_error=True)
|