Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from fastapi.staticfiles import StaticFiles
|
|
7 |
|
8 |
css_code = os.getenv("DazDinGo_CSS")
|
9 |
|
10 |
-
#
|
11 |
os.makedirs("/tmp/flux_images", exist_ok=True)
|
12 |
|
13 |
def load_fn(models):
|
@@ -23,9 +23,6 @@ def load_fn(models):
|
|
23 |
|
24 |
load_fn(models)
|
25 |
|
26 |
-
num_models = len(models)
|
27 |
-
default_models = models[:num_models]
|
28 |
-
|
29 |
def save_image_to_tmp(image):
|
30 |
if image is None:
|
31 |
return None
|
@@ -41,58 +38,81 @@ def gen_fn(model_str, prompt):
|
|
41 |
klir = '| ultra detail, ultra elaboration, ultra quality, perfect'
|
42 |
result = models_load[model_str](f'{prompt} {klir} {noise}')
|
43 |
|
44 |
-
# Simpan gambar ke /tmp dan dapatkan URL
|
45 |
if isinstance(result, list):
|
46 |
return [save_image_to_tmp(img) for img in result]
|
47 |
-
|
48 |
-
return save_image_to_tmp(result)
|
49 |
|
50 |
-
def
|
51 |
-
with gr.
|
52 |
-
with gr.
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
object_fit="contain",
|
76 |
-
show_download_button=True,
|
77 |
-
elem_id="custom_gallery")
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
-
make_me()
|
92 |
|
93 |
-
#
|
94 |
app = demo.app
|
95 |
app.mount("/file", StaticFiles(directory="/tmp"), name="static")
|
96 |
|
97 |
-
|
98 |
-
demo.launch()
|
|
|
7 |
|
8 |
css_code = os.getenv("DazDinGo_CSS")
|
9 |
|
10 |
+
# Create /tmp directory if it doesn't exist
|
11 |
os.makedirs("/tmp/flux_images", exist_ok=True)
|
12 |
|
13 |
def load_fn(models):
|
|
|
23 |
|
24 |
load_fn(models)
|
25 |
|
|
|
|
|
|
|
26 |
def save_image_to_tmp(image):
|
27 |
if image is None:
|
28 |
return None
|
|
|
38 |
klir = '| ultra detail, ultra elaboration, ultra quality, perfect'
|
39 |
result = models_load[model_str](f'{prompt} {klir} {noise}')
|
40 |
|
|
|
41 |
if isinstance(result, list):
|
42 |
return [save_image_to_tmp(img) for img in result]
|
43 |
+
return save_image_to_tmp(result)
|
|
|
44 |
|
45 |
+
def create_interface():
|
46 |
+
with gr.Blocks(css=css_code) as demo:
|
47 |
+
with gr.Row():
|
48 |
+
with gr.Column(scale=4):
|
49 |
+
txt_input = gr.Textbox(
|
50 |
+
label='Your prompt:',
|
51 |
+
lines=4,
|
52 |
+
container=False,
|
53 |
+
elem_id="custom_textbox",
|
54 |
+
placeholder="Prompt"
|
55 |
+
)
|
56 |
|
57 |
+
with gr.Column(scale=1):
|
58 |
+
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
59 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
60 |
+
|
61 |
+
def toggle_buttons():
|
62 |
+
return [
|
63 |
+
gr.Button(interactive=False),
|
64 |
+
gr.Button(interactive=True)
|
65 |
+
]
|
66 |
+
|
67 |
+
gen_button.click(
|
68 |
+
fn=toggle_buttons,
|
69 |
+
outputs=[gen_button, stop_button]
|
70 |
+
)
|
71 |
+
|
72 |
+
stop_button.click(
|
73 |
+
fn=lambda: [gr.Button(interactive=True), gr.Button(interactive=False)],
|
74 |
+
outputs=[gen_button, stop_button]
|
75 |
+
)
|
76 |
+
|
77 |
+
with gr.Row():
|
78 |
+
output = gr.Gallery(
|
79 |
+
label="Generated Images",
|
80 |
+
columns=3,
|
81 |
+
height="auto",
|
82 |
+
object_fit="contain",
|
83 |
+
show_download_button=True,
|
84 |
+
elem_id="custom_gallery"
|
85 |
+
)
|
86 |
|
87 |
+
model_selector = gr.Dropdown(
|
88 |
+
models,
|
89 |
+
label="Select LoRA Model",
|
90 |
+
value=models[0] if models else None,
|
91 |
+
multiselect=False,
|
92 |
+
interactive=True,
|
93 |
+
elem_id="custom_dropdown"
|
94 |
+
)
|
|
|
|
|
|
|
95 |
|
96 |
+
# Store the generation event to be able to cancel it
|
97 |
+
gen_event = gen_button.click(
|
98 |
+
fn=gen_fn,
|
99 |
+
inputs=[model_selector, txt_input],
|
100 |
+
outputs=output
|
101 |
+
)
|
102 |
+
|
103 |
+
stop_button.click(
|
104 |
+
fn=None,
|
105 |
+
cancels=[gen_event],
|
106 |
+
outputs=[gen_button, stop_button]
|
107 |
+
)
|
108 |
+
|
109 |
+
return demo
|
110 |
|
111 |
+
demo = create_interface()
|
|
|
112 |
|
113 |
+
# Configure static files serving
|
114 |
app = demo.app
|
115 |
app.mount("/file", StaticFiles(directory="/tmp"), name="static")
|
116 |
|
117 |
+
if __name__ == "__main__":
|
118 |
+
demo.queue(concurrency_count=50).launch()
|