Deddy commited on
Commit
2fdf5b4
1 Parent(s): 50b4337

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +184 -0
  2. assets/banner.jpg +0 -0
  3. requirements.txt +3 -0
  4. themes.py +55 -0
app.py ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio_client import Client, handle_file
2
+ import gradio as gr
3
+ import concurrent.futures
4
+ import tempfile
5
+ from PIL import Image
6
+
7
+ # Impor tema custom dari themes.py
8
+ from themes import IndonesiaTheme
9
+
10
+ # Siapkan URL dan header untuk permintaan API
11
+ url_api1 = os.environ['url_api1']
12
+ url_api2 = os.environ['url_api2']
13
+
14
+ # Fungsi untuk FLUX Std
15
+ def infer_image(prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress()):
16
+ client = Client(url_api1)
17
+ try:
18
+ progress(0, "Memulai proses...")
19
+ result = client.predict(
20
+ prompt=prompt,
21
+ seed=seed,
22
+ randomize_seed=randomize_seed,
23
+ width=width,
24
+ height=height,
25
+ guidance_scale=guidance_scale,
26
+ num_inference_steps=num_inference_steps,
27
+ api_name="/infer"
28
+ )
29
+ progress(1, "Proses selesai.")
30
+ return result[0], seed if not randomize_seed else result[1]
31
+ except concurrent.futures.CancelledError:
32
+ return None, "Request was cancelled. Please try again."
33
+
34
+ # Fungsi untuk FLUX Inpainting
35
+ def inpainting_process(input_image_editor, input_text, seed_slicer, randomize_seed_checkbox, strength_slider, num_inference_steps_slider, progress=gr.Progress()):
36
+ client = Client(url_api2)
37
+ try:
38
+ progress(0, "Memulai proses inpainting...")
39
+
40
+ # Simpan gambar sementara ke file
41
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp:
42
+ input_image_editor["composite"].save(temp.name)
43
+ temp_image_path = temp.name
44
+
45
+ # Tutup file setelah penulisan selesai
46
+ temp.close()
47
+
48
+ # Gunakan handle_file untuk memproses gambar dari jalur file sementara
49
+ input_image_editor = {"background": handle_file(temp_image_path)}
50
+
51
+ result = client.predict(
52
+ input_image_editor=input_image_editor,
53
+ input_text=input_text,
54
+ seed_slicer=seed_slicer,
55
+ randomize_seed_checkbox=randomize_seed_checkbox,
56
+ strength_slider=strength_slider,
57
+ num_inference_steps_slider=num_inference_steps_slider,
58
+ api_name="/process"
59
+ )
60
+ progress(1, "Proses inpainting selesai.")
61
+ return result[0], result[1]
62
+ except concurrent.futures.CancelledError:
63
+ return None, "Request was cancelled. Please try again."
64
+ finally:
65
+ # Hapus file sementara setelah selesai digunakan
66
+ import os
67
+ os.remove(temp_image_path)
68
+
69
+ # CSS untuk styling antarmuka
70
+ css = """
71
+ #col-left, #col-mid, #col-right {
72
+ margin: 0 auto;
73
+ max-width: 400px;
74
+ padding: 10px;
75
+ border-radius: 15px;
76
+ background-color: #f9f9f9;
77
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
78
+ }
79
+ #banner {
80
+ width: 100%;
81
+ text-align: center;
82
+ margin-bottom: 20px;
83
+ }
84
+ #run-button {
85
+ background-color: #ff4b5c;
86
+ color: white;
87
+ font-weight: bold;
88
+ padding: 10px;
89
+ border-radius: 10px;
90
+ cursor: pointer;
91
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
92
+ }
93
+ #footer {
94
+ text-align: center;
95
+ margin-top: 20px;
96
+ color: silver;
97
+ }
98
+ """
99
+
100
+ # Interface Gradio
101
+ with gr.Blocks(css=css, theme=IndonesiaTheme()) as app:
102
+ # Tambahkan banner
103
+ gr.HTML("""
104
+ <div style='text-align: center;'>
105
+ <img src='https://i.postimg.cc/ZYFNKrjK/banner.jpg' alt='Banner' style='width: 100%; height: auto;'/>
106
+ </div>
107
+ """)
108
+
109
+ # Ganti judul
110
+ gr.Markdown("<h2 style='text-align: center;'>FLUX.1 Untuk membuat gambar terbaik di dunia.</h2>")
111
+ gr.HTML("""
112
+ <h4 style='text-align: center;'>
113
+ <a href="https://huggingface.co/sayakpaul/FLUX.1-merged">FLUX.1 [merged]</a> Merge by
114
+ <a href="https://huggingface.co/sayakpaul">Sayak Paul</a> of 2 of the 12B param rectified flow transformers
115
+ <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev">FLUX.1 [dev]</a> and
116
+ <a href="https://huggingface.co/black-forest-labs/FLUX.1-schnell">FLUX.1 [schnell]</a> by
117
+ <a href="https://blackforestlabs.ai/">Black Forest Labs</a>, created by
118
+ <a href="https://github.com/drat">Deddy</a>
119
+ </h4>
120
+ """)
121
+
122
+ with gr.Tabs():
123
+ with gr.TabItem("FLUX Std"):
124
+ with gr.Row():
125
+ with gr.Column():
126
+ prompt_input = gr.Textbox(label="Prompt", placeholder="Ceritakan tentang image apa yang ingin dibuat...")
127
+ seed_slider = gr.Slider(label="Seed", minimum=0, maximum=10000, step=1, value=0)
128
+ randomize_seed_checkbox = gr.Checkbox(label="Randomize Seed", value=True)
129
+ width_slider = gr.Slider(label="Lebar", minimum=512, maximum=2048, step=64, value=1024)
130
+ height_slider = gr.Slider(label="Tinggi", minimum=512, maximum=2048, step=64, value=1024)
131
+ guidance_scale_slider = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, step=0.5, value=3.5)
132
+ inference_steps_slider = gr.Slider(label="Jumlah Inference Steps", minimum=1, maximum=50, step=1, value=8)
133
+ submit_button = gr.Button("Mulai Membuat Gambar", elem_id="run-button")
134
+
135
+ with gr.Column():
136
+ result_image = gr.Image(label="Result")
137
+ seed_output = gr.Number(label="Seed Digunakan")
138
+
139
+ submit_button.click(
140
+ infer_image,
141
+ inputs=[prompt_input, seed_slider, randomize_seed_checkbox, width_slider, height_slider, guidance_scale_slider, inference_steps_slider],
142
+ outputs=[result_image, seed_output],
143
+ show_progress=True # Menampilkan progress bar
144
+ )
145
+
146
+ with gr.TabItem("FLUX Inpainting"):
147
+ with gr.Row():
148
+ with gr.Column():
149
+ input_image_editor = gr.ImageEditor(
150
+ label='Image',
151
+ type='pil',
152
+ sources=["upload", "webcam"],
153
+ image_mode='RGB',
154
+ layers=False,
155
+ brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
156
+
157
+ input_text = gr.Textbox(label="Prompt", placeholder="Deskripsi untuk inpainting...")
158
+ seed_slicer = gr.Slider(label="Seed", minimum=0, maximum=10000, step=1, value=42)
159
+ randomize_seed_checkbox = gr.Checkbox(label="Randomize Seed", value=True)
160
+ strength_slider = gr.Slider(label="Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.85)
161
+ num_inference_steps_slider = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=50, step=1, value=20)
162
+ inpainting_button = gr.Button("Mulai Proses Inpainting", elem_id="run-button")
163
+
164
+ with gr.Column():
165
+ generated_image = gr.Image(label="Generated Image")
166
+ input_mask = gr.Image(label="Input Mask")
167
+
168
+ inpainting_button.click(
169
+ inpainting_process,
170
+ inputs=[input_image_editor, input_text, seed_slicer, randomize_seed_checkbox, strength_slider, num_inference_steps_slider],
171
+ outputs=[generated_image, input_mask],
172
+ show_progress=True # Menampilkan progress bar
173
+ )
174
+
175
+ # Tambahkan footer di bagian bawah
176
+ gr.HTML("""
177
+ <footer id="footer">
178
+ Transfer Energi Semesta Digital © 2024 __drat. | 🇮🇩 Untuk Indonesia Jaya!
179
+ </footer>
180
+ """)
181
+
182
+ # Meluncurkan aplikasi
183
+ if __name__ == "__main__":
184
+ app.launch()
assets/banner.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ gradio_client
3
+ Pillow
themes.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from typing import Iterable
3
+ from gradio.themes.base import Base
4
+ from gradio.themes.utils import colors, fonts, sizes
5
+
6
+ class IndonesiaTheme(Base):
7
+ def __init__(
8
+ self,
9
+ *,
10
+ primary_hue: colors.Color | str = colors.red,
11
+ secondary_hue: colors.Color | str = colors.gray,
12
+ neutral_hue: colors.Color | str = colors.gray,
13
+ spacing_size: sizes.Size | str = sizes.spacing_md,
14
+ radius_size: sizes.Size | str = sizes.radius_md,
15
+ text_size: sizes.Size | str = sizes.text_lg,
16
+ font: fonts.Font
17
+ | str
18
+ | Iterable[fonts.Font | str] = (
19
+ fonts.GoogleFont("Quicksand"),
20
+ "ui-sans-serif",
21
+ "sans-serif",
22
+ ),
23
+ font_mono: fonts.Font
24
+ | str
25
+ | Iterable[fonts.Font | str] = (
26
+ fonts.GoogleFont("IBM Plex Mono"),
27
+ "ui-monospace",
28
+ "monospace",
29
+ ),
30
+ ):
31
+ super().__init__(
32
+ primary_hue=primary_hue,
33
+ secondary_hue=secondary_hue,
34
+ neutral_hue=neutral_hue,
35
+ spacing_size=spacing_size,
36
+ radius_size=radius_size,
37
+ text_size=text_size,
38
+ font=font,
39
+ font_mono=font_mono,
40
+ )
41
+ super().set(
42
+ body_background_fill="linear-gradient(to bottom, #e0e0e0, #7d7d7d)", # Gradasi abu-abu muda ke abu-abu tua
43
+ body_background_fill_dark="linear-gradient(to bottom, #7d7d7d, #4a4a4a)", # Gradasi abu-abu tua ke lebih gelap untuk dark mode
44
+ button_primary_background_fill="linear-gradient(90deg, #d84a4a, #b33030)", # Merah ke merah tua
45
+ button_primary_background_fill_hover="linear-gradient(90deg, #e85b5b, #cc4b4b)", # Merah lebih terang untuk hover
46
+ button_primary_text_color="white",
47
+ button_primary_background_fill_dark="linear-gradient(90deg, #b33030, #8f1f1f)", # Merah tua untuk dark mode
48
+ slider_color="*secondary_300",
49
+ slider_color_dark="*secondary_600",
50
+ block_title_text_weight="600",
51
+ block_border_width="3px",
52
+ block_shadow="*shadow_drop_lg",
53
+ button_shadow="*shadow_drop_lg",
54
+ button_large_padding="32px",
55
+ )