Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,8 @@ import torch
|
|
9 |
from diffusers import DiffusionPipeline
|
10 |
from PIL import Image
|
11 |
|
12 |
-
# Create permanent storage directory
|
13 |
-
SAVE_DIR =
|
14 |
if not os.path.exists(SAVE_DIR):
|
15 |
os.makedirs(SAVE_DIR, exist_ok=True)
|
16 |
|
@@ -53,17 +53,6 @@ def load_generated_images():
|
|
53 |
image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
|
54 |
return image_files
|
55 |
|
56 |
-
class ImageFlagging(gr.FlaggingCallback):
|
57 |
-
def setup(self, components, flagging_dir: str):
|
58 |
-
self.components = components
|
59 |
-
self.flagging_dir = SAVE_DIR
|
60 |
-
|
61 |
-
def flag(self, flag_data, flag_option=None, flag_index=None, username=None) -> int:
|
62 |
-
"""Save image and metadata permanently"""
|
63 |
-
image, prompt = flag_data
|
64 |
-
filepath = save_generated_image(image, prompt)
|
65 |
-
return 0
|
66 |
-
|
67 |
def load_predefined_images():
|
68 |
predefined_images = [
|
69 |
"assets/cm1.webp",
|
@@ -101,8 +90,8 @@ def inference(
|
|
101 |
joint_attention_kwargs={"scale": lora_scale},
|
102 |
).images[0]
|
103 |
|
104 |
-
# Save the generated image
|
105 |
-
save_generated_image(image, prompt)
|
106 |
|
107 |
# Return the image, seed, and updated gallery
|
108 |
return image, seed, load_generated_images()
|
@@ -122,9 +111,7 @@ footer {
|
|
122 |
}
|
123 |
"""
|
124 |
|
125 |
-
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
126 |
-
flagging_callback = ImageFlagging()
|
127 |
-
|
128 |
gr.HTML('<div class="title"> Claude Monet STUDIO </div>')
|
129 |
gr.HTML('<div class="title">😄Image to Video Explore: <a href="https://huggingface.co/spaces/ginigen/theater" target="_blank">https://huggingface.co/spaces/ginigen/theater</a></div>')
|
130 |
|
@@ -199,25 +186,37 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
199 |
)
|
200 |
|
201 |
with gr.Tab("Gallery"):
|
|
|
202 |
generated_gallery = gr.Gallery(
|
203 |
label="Generated Images",
|
204 |
columns=6,
|
205 |
show_label=False,
|
206 |
value=load_generated_images(),
|
207 |
-
elem_id="generated_gallery"
|
|
|
208 |
)
|
|
|
209 |
|
210 |
# Add sample gallery section at the bottom
|
211 |
gr.Markdown("### Claude Monet Style Examples")
|
212 |
predefined_gallery = gr.Gallery(
|
213 |
label="Sample Images",
|
214 |
-
columns=3,
|
215 |
rows=2,
|
216 |
show_label=False,
|
217 |
value=load_predefined_images()
|
218 |
)
|
219 |
|
220 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
gr.on(
|
222 |
triggers=[run_button.click, prompt.submit],
|
223 |
fn=inference,
|
@@ -232,12 +231,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
232 |
lora_scale,
|
233 |
],
|
234 |
outputs=[result, seed, generated_gallery],
|
235 |
-
).then(
|
236 |
-
fn=None,
|
237 |
-
inputs=[result, prompt],
|
238 |
-
outputs=None,
|
239 |
-
_js="(res, prompt) => clearInterval(window.GalleryIntervalID)",
|
240 |
-
flagging_callback=flagging_callback
|
241 |
)
|
242 |
|
243 |
demo.queue()
|
|
|
9 |
from diffusers import DiffusionPipeline
|
10 |
from PIL import Image
|
11 |
|
12 |
+
# Create permanent storage directory
|
13 |
+
SAVE_DIR = "saved_images" # Gradio will handle the persistence
|
14 |
if not os.path.exists(SAVE_DIR):
|
15 |
os.makedirs(SAVE_DIR, exist_ok=True)
|
16 |
|
|
|
53 |
image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
|
54 |
return image_files
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
def load_predefined_images():
|
57 |
predefined_images = [
|
58 |
"assets/cm1.webp",
|
|
|
90 |
joint_attention_kwargs={"scale": lora_scale},
|
91 |
).images[0]
|
92 |
|
93 |
+
# Save the generated image
|
94 |
+
filepath = save_generated_image(image, prompt)
|
95 |
|
96 |
# Return the image, seed, and updated gallery
|
97 |
return image, seed, load_generated_images()
|
|
|
111 |
}
|
112 |
"""
|
113 |
|
114 |
+
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, analytics_enabled=False) as demo:
|
|
|
|
|
115 |
gr.HTML('<div class="title"> Claude Monet STUDIO </div>')
|
116 |
gr.HTML('<div class="title">😄Image to Video Explore: <a href="https://huggingface.co/spaces/ginigen/theater" target="_blank">https://huggingface.co/spaces/ginigen/theater</a></div>')
|
117 |
|
|
|
186 |
)
|
187 |
|
188 |
with gr.Tab("Gallery"):
|
189 |
+
gallery_header = gr.Markdown("### Generated Images Gallery")
|
190 |
generated_gallery = gr.Gallery(
|
191 |
label="Generated Images",
|
192 |
columns=6,
|
193 |
show_label=False,
|
194 |
value=load_generated_images(),
|
195 |
+
elem_id="generated_gallery",
|
196 |
+
height="auto"
|
197 |
)
|
198 |
+
refresh_btn = gr.Button("🔄 Refresh Gallery")
|
199 |
|
200 |
# Add sample gallery section at the bottom
|
201 |
gr.Markdown("### Claude Monet Style Examples")
|
202 |
predefined_gallery = gr.Gallery(
|
203 |
label="Sample Images",
|
204 |
+
columns=3,
|
205 |
rows=2,
|
206 |
show_label=False,
|
207 |
value=load_predefined_images()
|
208 |
)
|
209 |
|
210 |
+
# Event handlers
|
211 |
+
def refresh_gallery():
|
212 |
+
return load_generated_images()
|
213 |
+
|
214 |
+
refresh_btn.click(
|
215 |
+
fn=refresh_gallery,
|
216 |
+
inputs=None,
|
217 |
+
outputs=generated_gallery,
|
218 |
+
)
|
219 |
+
|
220 |
gr.on(
|
221 |
triggers=[run_button.click, prompt.submit],
|
222 |
fn=inference,
|
|
|
231 |
lora_scale,
|
232 |
],
|
233 |
outputs=[result, seed, generated_gallery],
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
)
|
235 |
|
236 |
demo.queue()
|