Update app.py
Browse files
app.py
CHANGED
@@ -122,7 +122,7 @@ def generate_item(tag, ideas, max_retries=3):
|
|
122 |
image_response = client.models.generate_images(
|
123 |
model='imagen-3.0-generate-002',
|
124 |
prompt=image_prompt,
|
125 |
-
config=types.
|
126 |
number_of_images=1,
|
127 |
aspect_ratio="9:16",
|
128 |
person_generation="DONT_ALLOW"
|
@@ -289,68 +289,82 @@ def load_previous(tag, current_index, feed_items):
|
|
289 |
|
290 |
def generate_share_links(image_base64, caption):
|
291 |
"""
|
292 |
-
Generate share links for social media platforms.
|
293 |
|
294 |
Args:
|
295 |
image_base64 (str): The base64-encoded image data.
|
296 |
caption (str): The caption to share with the image.
|
297 |
|
298 |
Returns:
|
299 |
-
str: HTML string with share links.
|
300 |
"""
|
301 |
-
# Create a data URL for the image
|
302 |
image_data_url = f"data:image/png;base64,{image_base64}"
|
303 |
encoded_caption = urllib.parse.quote(caption)
|
304 |
-
encoded_image_url = urllib.parse.quote(image_data_url)
|
305 |
|
306 |
-
# Generate share links
|
307 |
share_links = """
|
308 |
<div style="
|
309 |
display: flex;
|
310 |
-
flex-
|
311 |
-
|
312 |
gap: 10px;
|
313 |
margin-top: 10px;
|
314 |
color: white;
|
315 |
font-family: Arial, sans-serif;
|
316 |
">
|
317 |
-
<
|
318 |
-
|
319 |
-
color: #
|
320 |
-
padding: 5px 10px;
|
321 |
-
border-radius: 5px;
|
322 |
-
text-decoration: none;
|
323 |
-
">Share on TikTok</a>
|
324 |
-
<a href="https://www.instagram.com/?url={image_url}&caption={caption}" target="_blank" style="
|
325 |
-
background-color: #e1306c;
|
326 |
-
color: white;
|
327 |
-
padding: 5px 10px;
|
328 |
-
border-radius: 5px;
|
329 |
-
text-decoration: none;
|
330 |
-
">Share on Instagram</a>
|
331 |
-
<a href="https://www.facebook.com/sharer/sharer.php?u={image_url}"e={caption}" target="_blank" style="
|
332 |
-
background-color: #4267b2;
|
333 |
-
color: white;
|
334 |
-
padding: 5px 10px;
|
335 |
-
border-radius: 5px;
|
336 |
-
text-decoration: none;
|
337 |
-
">Share on Facebook</a>
|
338 |
-
<a href="https://twitter.com/intent/tweet?text={caption}&url={image_url}" target="_blank" style="
|
339 |
-
background-color: #1da1f2;
|
340 |
color: white;
|
341 |
padding: 5px 10px;
|
342 |
border-radius: 5px;
|
343 |
text-decoration: none;
|
344 |
-
">
|
345 |
-
<
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
</div>
|
353 |
-
""".format(
|
354 |
|
355 |
return share_links
|
356 |
|
@@ -531,7 +545,7 @@ with gr.Blocks(
|
|
531 |
.gr-button { width: 100%; margin-top: 10px; }
|
532 |
.gr-form { background-color: #111; padding: 15px; border-radius: 10px; }
|
533 |
""",
|
534 |
-
title="Create Your Feed"
|
535 |
) as demo:
|
536 |
# State variables
|
537 |
current_tag = gr.State(value="")
|
|
|
122 |
image_response = client.models.generate_images(
|
123 |
model='imagen-3.0-generate-002',
|
124 |
prompt=image_prompt,
|
125 |
+
config=types.GenerateContentConfig(
|
126 |
number_of_images=1,
|
127 |
aspect_ratio="9:16",
|
128 |
person_generation="DONT_ALLOW"
|
|
|
289 |
|
290 |
def generate_share_links(image_base64, caption):
|
291 |
"""
|
292 |
+
Generate share links for social media platforms with a download link.
|
293 |
|
294 |
Args:
|
295 |
image_base64 (str): The base64-encoded image data.
|
296 |
caption (str): The caption to share with the image.
|
297 |
|
298 |
Returns:
|
299 |
+
str: HTML string with share links and download instructions.
|
300 |
"""
|
|
|
301 |
image_data_url = f"data:image/png;base64,{image_base64}"
|
302 |
encoded_caption = urllib.parse.quote(caption)
|
|
|
303 |
|
304 |
+
# Generate share links with instructions to download the image
|
305 |
share_links = """
|
306 |
<div style="
|
307 |
display: flex;
|
308 |
+
flex-direction: column;
|
309 |
+
align-items: center;
|
310 |
gap: 10px;
|
311 |
margin-top: 10px;
|
312 |
color: white;
|
313 |
font-family: Arial, sans-serif;
|
314 |
">
|
315 |
+
<p style="text-align: center;">To share, download the image and upload it to your platform:</p>
|
316 |
+
<a href="{image_url}" download="feed_item.png" style="
|
317 |
+
background-color: #4CAF50;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
color: white;
|
319 |
padding: 5px 10px;
|
320 |
border-radius: 5px;
|
321 |
text-decoration: none;
|
322 |
+
">Download Image</a>
|
323 |
+
<div style="
|
324 |
+
display: flex;
|
325 |
+
flex-wrap: wrap;
|
326 |
+
justify-content: center;
|
327 |
+
gap: 10px;
|
328 |
+
margin-top: 10px;
|
329 |
+
">
|
330 |
+
<a href="https://www.tiktok.com/upload?caption={caption}" target="_blank" style="
|
331 |
+
background-color: #00f2ea;
|
332 |
+
color: #000;
|
333 |
+
padding: 5px 10px;
|
334 |
+
border-radius: 5px;
|
335 |
+
text-decoration: none;
|
336 |
+
">Share on TikTok</a>
|
337 |
+
<a href="https://www.instagram.com/?caption={caption}" target="_blank" style="
|
338 |
+
background-color: #e1306c;
|
339 |
+
color: white;
|
340 |
+
padding: 5px 10px;
|
341 |
+
border-radius: 5px;
|
342 |
+
text-decoration: none;
|
343 |
+
">Share on Instagram</a>
|
344 |
+
<a href="https://www.facebook.com/sharer/sharer.php?quote={caption}" target="_blank" style="
|
345 |
+
background-color: #4267b2;
|
346 |
+
color: white;
|
347 |
+
padding: 5px 10px;
|
348 |
+
border-radius: 5px;
|
349 |
+
text-decoration: none;
|
350 |
+
">Share on Facebook</a>
|
351 |
+
<a href="https://twitter.com/intent/tweet?text={caption}" target="_blank" style="
|
352 |
+
background-color: #1da1f2;
|
353 |
+
color: white;
|
354 |
+
padding: 5px 10px;
|
355 |
+
border-radius: 5px;
|
356 |
+
text-decoration: none;
|
357 |
+
">Share on X</a>
|
358 |
+
<a href="https://pinterest.com/pin/create/button/?description={caption}" target="_blank" style="
|
359 |
+
background-color: #bd081c;
|
360 |
+
color: white;
|
361 |
+
padding: 5px 10px;
|
362 |
+
border-radius: 5px;
|
363 |
+
text-decoration: none;
|
364 |
+
">Share on Pinterest</a>
|
365 |
+
</div>
|
366 |
</div>
|
367 |
+
""".format(image_url=image_data_url, caption=encoded_caption)
|
368 |
|
369 |
return share_links
|
370 |
|
|
|
545 |
.gr-button { width: 100%; margin-top: 10px; }
|
546 |
.gr-form { background-color: #111; padding: 15px; border-radius: 10px; }
|
547 |
""",
|
548 |
+
title="Create Your Feed"
|
549 |
) as demo:
|
550 |
# State variables
|
551 |
current_tag = gr.State(value="")
|