Spaces:
Runtime error
Runtime error
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 |
-
#
|
13 |
-
SAVE_DIR = "saved_images" # Gradio
|
14 |
if not os.path.exists(SAVE_DIR):
|
15 |
os.makedirs(SAVE_DIR, exist_ok=True)
|
16 |
|
@@ -26,16 +26,15 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
26 |
MAX_IMAGE_SIZE = 1024
|
27 |
|
28 |
def save_generated_image(image, prompt):
|
29 |
-
# Generate unique filename with timestamp
|
30 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
31 |
unique_id = str(uuid.uuid4())[:8]
|
32 |
filename = f"{timestamp}_{unique_id}.png"
|
33 |
filepath = os.path.join(SAVE_DIR, filename)
|
34 |
|
35 |
-
#
|
36 |
image.save(filepath)
|
37 |
|
38 |
-
#
|
39 |
metadata_file = os.path.join(SAVE_DIR, "metadata.txt")
|
40 |
with open(metadata_file, "a", encoding="utf-8") as f:
|
41 |
f.write(f"{filename}|{prompt}|{timestamp}\n")
|
@@ -46,22 +45,28 @@ def load_generated_images():
|
|
46 |
if not os.path.exists(SAVE_DIR):
|
47 |
return []
|
48 |
|
49 |
-
#
|
50 |
image_files = [
|
51 |
os.path.join(SAVE_DIR, f)
|
52 |
for f in os.listdir(SAVE_DIR)
|
53 |
if f.endswith(('.png', '.jpg', '.jpeg', '.webp'))
|
54 |
]
|
55 |
-
#
|
56 |
image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
|
57 |
return image_files
|
58 |
|
59 |
def load_predefined_images():
|
60 |
-
#
|
61 |
return []
|
62 |
|
63 |
-
# ๊ฐ๋จํ CSS: ํ์ดํ ํฌ๊ธฐ, ์ค์ ์ ๋ ฌ, footer ์จ๊น ๋ฑ
|
64 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
.title {
|
66 |
font-size: 1.8em;
|
67 |
font-weight: bold;
|
@@ -99,30 +104,25 @@ def inference(
|
|
99 |
joint_attention_kwargs={"scale": lora_scale},
|
100 |
).images[0]
|
101 |
|
102 |
-
# Save the generated image
|
103 |
filepath = save_generated_image(image, prompt)
|
104 |
-
|
105 |
-
# Return the image, seed, and updated gallery
|
106 |
return image, seed, load_generated_images()
|
107 |
|
|
|
|
|
108 |
examples = [
|
109 |
"Pepe the frog playing fetch with a golden retriever in a sunny park. He wears casual weekend clothes and tosses a bright red frisbee with a goofy grin. The dog leaps gracefully through the air, tail wagging with excitement. The warm afternoon sunlight filters through the trees, creating a humorous meme-like atmosphere. [pepe]",
|
110 |
-
|
111 |
"Pepe the frog dressed in full military gear, standing at attention with a standard-issue rifle. His crisp uniform is adorned with cartoonish medals. Other frog soldiers march in formation behind him during a grand meme parade, conveying discipline mixed with comical charm. [pepe]",
|
112 |
-
|
113 |
"A medieval Pepe knight in gleaming armor, proudly holding an ornate sword and shield. He stands in front of a majestic castle with a swirling moat. His shield features a cartoon frog crest, and sunlight gleams off his polished armor, adding a humorous yet epic feel. [pepe]",
|
114 |
-
|
115 |
"A charismatic Pepe the frog addressing a crowd from a podium. He wears a well-fitted suit and gestures with exaggerated cartoon expressions while speaking. The audience is filled with fellow frog characters holding supportive banners. Cameras capture this grand meme moment. [pepe]",
|
116 |
-
|
117 |
"Pepe the frog enjoying a peaceful morning at home, reading a newspaper at his kitchen table. He wears comfy pajamas and sips coffee from a novelty frog mug. Sunlight streams through the window, illuminating a quaint plant on the countertop in this cozy, meme-inspired scene. [pepe]",
|
118 |
-
|
119 |
"Businessman Pepe walking confidently through a sleek office lobby, briefcase in hand. He wears a tailored navy suit, and his wide frog eyes convey determination. Floor-to-ceiling windows reveal a bustling cityscape behind him, blending corporate professionalism with meme humor. [pepe]"
|
120 |
]
|
121 |
|
122 |
|
123 |
-
#
|
124 |
-
|
125 |
-
|
|
|
126 |
|
127 |
gr.HTML("""
|
128 |
<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fopenfree-pepe.hf.space">
|
@@ -153,7 +153,10 @@ with gr.Blocks(css=css, analytics_enabled=False) as demo:
|
|
153 |
step=1,
|
154 |
value=42,
|
155 |
)
|
156 |
-
randomize_seed = gr.Checkbox(
|
|
|
|
|
|
|
157 |
|
158 |
with gr.Row():
|
159 |
width = gr.Slider(
|
@@ -201,7 +204,7 @@ with gr.Blocks(css=css, analytics_enabled=False) as demo:
|
|
201 |
)
|
202 |
|
203 |
with gr.Tab("Gallery"):
|
204 |
-
|
205 |
generated_gallery = gr.Gallery(
|
206 |
label="Generated Images",
|
207 |
columns=6,
|
@@ -212,8 +215,7 @@ with gr.Blocks(css=css, analytics_enabled=False) as demo:
|
|
212 |
)
|
213 |
refresh_btn = gr.Button("๐ Refresh Gallery")
|
214 |
|
215 |
-
|
216 |
-
# Event handlers
|
217 |
def refresh_gallery():
|
218 |
return load_generated_images()
|
219 |
|
@@ -223,6 +225,7 @@ with gr.Blocks(css=css, analytics_enabled=False) as demo:
|
|
223 |
outputs=generated_gallery,
|
224 |
)
|
225 |
|
|
|
226 |
gr.on(
|
227 |
triggers=[run_button.click, prompt.submit],
|
228 |
fn=inference,
|
|
|
9 |
from diffusers import DiffusionPipeline
|
10 |
from PIL import Image
|
11 |
|
12 |
+
# ---------- ์ด๊ธฐ ์ค์ ๋ฐ ๋ชจ๋ธ ๋ก๋ ----------
|
13 |
+
SAVE_DIR = "saved_images" # Gradio๊ฐ ์ ์ฅ์ ๊ด๋ฆฌ๋ฅผ ์ํ
|
14 |
if not os.path.exists(SAVE_DIR):
|
15 |
os.makedirs(SAVE_DIR, exist_ok=True)
|
16 |
|
|
|
26 |
MAX_IMAGE_SIZE = 1024
|
27 |
|
28 |
def save_generated_image(image, prompt):
|
|
|
29 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
30 |
unique_id = str(uuid.uuid4())[:8]
|
31 |
filename = f"{timestamp}_{unique_id}.png"
|
32 |
filepath = os.path.join(SAVE_DIR, filename)
|
33 |
|
34 |
+
# ์ด๋ฏธ์ง ์ ์ฅ
|
35 |
image.save(filepath)
|
36 |
|
37 |
+
# ๋ฉํ๋ฐ์ดํฐ ์ ์ฅ
|
38 |
metadata_file = os.path.join(SAVE_DIR, "metadata.txt")
|
39 |
with open(metadata_file, "a", encoding="utf-8") as f:
|
40 |
f.write(f"{filename}|{prompt}|{timestamp}\n")
|
|
|
45 |
if not os.path.exists(SAVE_DIR):
|
46 |
return []
|
47 |
|
48 |
+
# ๋๋ ํ ๋ฆฌ ๋ด ์ด๋ฏธ์ง ํ์ผ ๋ก๋
|
49 |
image_files = [
|
50 |
os.path.join(SAVE_DIR, f)
|
51 |
for f in os.listdir(SAVE_DIR)
|
52 |
if f.endswith(('.png', '.jpg', '.jpeg', '.webp'))
|
53 |
]
|
54 |
+
# ์์ฑ ์๊ฐ ๊ธฐ์ค ์ ๋ ฌ (์ต์ ํ์ผ ์ฐ์ )
|
55 |
image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
|
56 |
return image_files
|
57 |
|
58 |
def load_predefined_images():
|
59 |
+
# ๋ณ๋ ์ฌ์ ์ด๋ฏธ์ง ์์
|
60 |
return []
|
61 |
|
|
|
62 |
css = """
|
63 |
+
/* ๋ฐฐ๊ฒฝ ๊ทธ๋ผ๋์ธํธ๋ฅผ ์ฃผ๊ฑฐ๋, ํฐํธ/ํ์ดํ ํฌ๊ธฐ ๋ฑ์ ์ํ๋ ๋๋ก ๊พธ๋ฐ ์ ์์ต๋๋ค. */
|
64 |
+
body {
|
65 |
+
font-family: 'Open Sans', sans-serif;
|
66 |
+
background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
|
67 |
+
margin: 0; /* ๊ธฐ๋ณธ ์ฌ๋ฐฑ ์ ๊ฑฐ */
|
68 |
+
padding: 0;
|
69 |
+
}
|
70 |
.title {
|
71 |
font-size: 1.8em;
|
72 |
font-weight: bold;
|
|
|
104 |
joint_attention_kwargs={"scale": lora_scale},
|
105 |
).images[0]
|
106 |
|
|
|
107 |
filepath = save_generated_image(image, prompt)
|
|
|
|
|
108 |
return image, seed, load_generated_images()
|
109 |
|
110 |
+
|
111 |
+
# ---------- ์์ ํ๋กฌํํธ ----------
|
112 |
examples = [
|
113 |
"Pepe the frog playing fetch with a golden retriever in a sunny park. He wears casual weekend clothes and tosses a bright red frisbee with a goofy grin. The dog leaps gracefully through the air, tail wagging with excitement. The warm afternoon sunlight filters through the trees, creating a humorous meme-like atmosphere. [pepe]",
|
|
|
114 |
"Pepe the frog dressed in full military gear, standing at attention with a standard-issue rifle. His crisp uniform is adorned with cartoonish medals. Other frog soldiers march in formation behind him during a grand meme parade, conveying discipline mixed with comical charm. [pepe]",
|
|
|
115 |
"A medieval Pepe knight in gleaming armor, proudly holding an ornate sword and shield. He stands in front of a majestic castle with a swirling moat. His shield features a cartoon frog crest, and sunlight gleams off his polished armor, adding a humorous yet epic feel. [pepe]",
|
|
|
116 |
"A charismatic Pepe the frog addressing a crowd from a podium. He wears a well-fitted suit and gestures with exaggerated cartoon expressions while speaking. The audience is filled with fellow frog characters holding supportive banners. Cameras capture this grand meme moment. [pepe]",
|
|
|
117 |
"Pepe the frog enjoying a peaceful morning at home, reading a newspaper at his kitchen table. He wears comfy pajamas and sips coffee from a novelty frog mug. Sunlight streams through the window, illuminating a quaint plant on the countertop in this cozy, meme-inspired scene. [pepe]",
|
|
|
118 |
"Businessman Pepe walking confidently through a sleek office lobby, briefcase in hand. He wears a tailored navy suit, and his wide frog eyes convey determination. Floor-to-ceiling windows reveal a bustling cityscape behind him, blending corporate professionalism with meme humor. [pepe]"
|
119 |
]
|
120 |
|
121 |
|
122 |
+
# ---------- UI ----------
|
123 |
+
# ์ํ๋ ๊ทธ๋ผ๋์ค ํ
๋ง๋ฅผ ์ ํํด ์ ์ฉํฉ๋๋ค. ์๋๋ Soft ํ
๋ง์ primary_hue="emerald"๋ฅผ ์ง์ ํ ์์์
๋๋ค.
|
124 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="emerald"), analytics_enabled=False) as demo:
|
125 |
+
gr.HTML('<div class="title">PEPE Meme Generator</div>')
|
126 |
|
127 |
gr.HTML("""
|
128 |
<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fopenfree-pepe.hf.space">
|
|
|
153 |
step=1,
|
154 |
value=42,
|
155 |
)
|
156 |
+
randomize_seed = gr.Checkbox(
|
157 |
+
label="Randomize seed",
|
158 |
+
value=True
|
159 |
+
)
|
160 |
|
161 |
with gr.Row():
|
162 |
width = gr.Slider(
|
|
|
204 |
)
|
205 |
|
206 |
with gr.Tab("Gallery"):
|
207 |
+
gr.Markdown("### Generated Images Gallery")
|
208 |
generated_gallery = gr.Gallery(
|
209 |
label="Generated Images",
|
210 |
columns=6,
|
|
|
215 |
)
|
216 |
refresh_btn = gr.Button("๐ Refresh Gallery")
|
217 |
|
218 |
+
# Gallery ์๋ก๊ณ ์นจ ํธ๋ค๋ฌ
|
|
|
219 |
def refresh_gallery():
|
220 |
return load_generated_images()
|
221 |
|
|
|
225 |
outputs=generated_gallery,
|
226 |
)
|
227 |
|
228 |
+
# Run ๋ฒํผ & ํ๋กฌํํธ ์
๋ ฅ ์ด๋ฒคํธ ์ฒ๋ฆฌ
|
229 |
gr.on(
|
230 |
triggers=[run_button.click, prompt.submit],
|
231 |
fn=inference,
|