Update app.py
Browse files
app.py
CHANGED
|
@@ -163,6 +163,67 @@ def generate_instagram_captions(description):
|
|
| 163 |
if not description.strip():
|
| 164 |
return "Please enter a description of your photo! πΈ"
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
# Enhanced cool captions database with complete, meaningful phrases
|
| 167 |
cool_captions = [
|
| 168 |
"Squad goals right here",
|
|
@@ -217,6 +278,14 @@ def generate_instagram_captions(description):
|
|
| 217 |
"Namaste all day long"
|
| 218 |
]
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
# Generate AI captions if model is available
|
| 221 |
ai_captions = []
|
| 222 |
if generator is not None:
|
|
@@ -227,8 +296,12 @@ def generate_instagram_captions(description):
|
|
| 227 |
ai_captions.append(caption)
|
| 228 |
attempts += 1
|
| 229 |
|
| 230 |
-
# Combine AI and predefined captions
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
# Remove duplicates while preserving order
|
| 234 |
seen = set()
|
|
@@ -256,7 +329,7 @@ def generate_instagram_captions(description):
|
|
| 256 |
if final_caption not in final_captions:
|
| 257 |
final_captions.append(final_caption)
|
| 258 |
|
| 259 |
-
# Format as numbered list
|
| 260 |
result = ""
|
| 261 |
emojis = ["π―", "β‘", "π", "π₯", "π«"]
|
| 262 |
|
|
@@ -287,18 +360,18 @@ instagram_css = """
|
|
| 287 |
font-family: 'Instagram Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
|
| 288 |
}
|
| 289 |
|
| 290 |
-
/* Header styling */
|
| 291 |
.main-header {
|
| 292 |
text-align: center;
|
| 293 |
-
|
| 294 |
-
-webkit-background-clip: text;
|
| 295 |
-
-webkit-text-fill-color: transparent;
|
| 296 |
-
background-clip: text;
|
| 297 |
font-size: 3em;
|
| 298 |
-
font-weight:
|
| 299 |
margin-bottom: 0.5em;
|
| 300 |
-
text-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 301 |
padding: 1rem 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
}
|
| 303 |
|
| 304 |
.subtitle {
|
|
@@ -464,7 +537,8 @@ with gr.Blocks(
|
|
| 464 |
title="InstaCap - AI Caption Generator"
|
| 465 |
) as demo:
|
| 466 |
|
| 467 |
-
|
|
|
|
| 468 |
gr.HTML('<p class="subtitle">Create short, catchy Instagram captions in seconds! Perfect for your social media posts β¨</p>')
|
| 469 |
|
| 470 |
with gr.Row():
|
|
@@ -493,25 +567,7 @@ with gr.Blocks(
|
|
| 493 |
elem_classes="output-box"
|
| 494 |
)
|
| 495 |
|
| 496 |
-
#
|
| 497 |
-
gr.Examples(
|
| 498 |
-
examples=[
|
| 499 |
-
["group photo with best friends at sunset"],
|
| 500 |
-
["coffee date with my bestie"],
|
| 501 |
-
["hiking adventure with the squad"],
|
| 502 |
-
["beach day with good vibes"],
|
| 503 |
-
["cozy movie night with favorites"],
|
| 504 |
-
["birthday celebration with everyone"],
|
| 505 |
-
["weekend brunch with the crew"],
|
| 506 |
-
["road trip memories being made"],
|
| 507 |
-
["concert night with amazing energy"],
|
| 508 |
-
["graduation day with family pride"]
|
| 509 |
-
],
|
| 510 |
-
inputs=description_input,
|
| 511 |
-
outputs=caption_output,
|
| 512 |
-
fn=generate_instagram_captions,
|
| 513 |
-
cache_examples=False
|
| 514 |
-
)
|
| 515 |
|
| 516 |
# Connect the button to the function
|
| 517 |
generate_btn.click(
|
|
|
|
| 163 |
if not description.strip():
|
| 164 |
return "Please enter a description of your photo! πΈ"
|
| 165 |
|
| 166 |
+
# Keyword-based caption training for specific contexts
|
| 167 |
+
keyword_captions = {
|
| 168 |
+
# Beach/Sea related
|
| 169 |
+
"beach": ["Hot and about", "Sun kissed skin", "Salt water heals everything", "Beach vibes only", "Sandy toes salty kisses"],
|
| 170 |
+
"sea": ["Hot and about", "Ocean child wild heart", "Sea you later", "Mermaid vibes activated", "Waves for days"],
|
| 171 |
+
"ocean": ["Hot and about", "Deep blue dreams", "Ocean therapy session", "Salty but sweet", "Endless summer vibes"],
|
| 172 |
+
"sand": ["Hot and about", "Sandy hair dont care", "Life is better", "Footprints in sand", "Sun sand and"],
|
| 173 |
+
"sun": ["Hot and about", "Chasing golden hour", "Sunshine on my mind", "Solar powered and happy", "Vitamin D loading"],
|
| 174 |
+
"sunset": ["Hot and about", "Golden hour magic", "Painted sky perfection", "Sunset state of mind", "Colors of happiness"],
|
| 175 |
+
"swimming": ["Hot and about", "Pool day vibes", "Making waves today", "Dive into happiness", "Swim your worries away"],
|
| 176 |
+
"surfing": ["Hot and about", "Riding the waves", "Salt life chosen", "Surf vibes activated", "Ocean is calling"],
|
| 177 |
+
|
| 178 |
+
# Food related
|
| 179 |
+
"food": ["Good food good mood", "Foodie life chosen", "Taste buds happy", "Eating my feelings", "Food coma incoming"],
|
| 180 |
+
"coffee": ["But first coffee", "Coffee and good vibes", "Espresso yourself freely", "Caffeine and confidence", "Morning fuel activated"],
|
| 181 |
+
"pizza": ["Pizza my heart", "Slice of heaven", "Cheesy and happy", "Pizza party vibes", "Life needs more pizza"],
|
| 182 |
+
"brunch": ["Brunch squad assembled", "Bottomless mimosa mood", "Weekend brunch vibes", "Eggs benedict bliss", "Brunch so hard"],
|
| 183 |
+
|
| 184 |
+
# Fitness/Health
|
| 185 |
+
"gym": ["Sweat now shine later", "Strong not skinny", "Gym life chosen", "Gains and glory", "Fitness is lifestyle"],
|
| 186 |
+
"workout": ["No pain no gain", "Sweat is fat crying", "Beast mode activated", "Stronger than yesterday", "Fitness addiction real"],
|
| 187 |
+
"yoga": ["Peace love and yoga", "Zen mode activated", "Namaste all day", "Breathe deeply live fully", "Inner peace found"],
|
| 188 |
+
"running": ["Run like you stole", "Miles and smiles", "Runner high achieved", "Pavement pounding therapy", "One step closer"],
|
| 189 |
+
|
| 190 |
+
# Travel/Adventure
|
| 191 |
+
"travel": ["Wanderlust and city dust", "Adventure awaits us", "Passport ready heart", "Collect moments not things", "Travel bug activated"],
|
| 192 |
+
"adventure": ["Adventure is out there", "Wild hearts cant", "Explore more worry less", "Adventure time activated", "Life is adventure"],
|
| 193 |
+
"hiking": ["Take only pictures", "Mountain therapy session", "Hike more worry less", "Trail blazing today", "Nature is medicine"],
|
| 194 |
+
"camping": ["Into the wild", "Campfire and chill", "Nature is home", "Unplugged and recharged", "Wild and free"],
|
| 195 |
+
|
| 196 |
+
# Party/Celebration
|
| 197 |
+
"party": ["Party like its", "Good times roll", "Dance floor ready", "Party mode activated", "Celebration time come"],
|
| 198 |
+
"birthday": ["Another year wiser", "Birthday vibes activated", "Cake and celebration", "Getting better with age", "Birthday squad assembled"],
|
| 199 |
+
"celebration": ["Cheers to good times", "Celebration mode activated", "Party till sunrise", "Good vibes only", "Making memories tonight"],
|
| 200 |
+
|
| 201 |
+
# Friends/Social
|
| 202 |
+
"friends": ["Squad goals right here", "Friends like these matter", "Good company great memories", "Squad deeper than ocean", "Friendship goals achieved"],
|
| 203 |
+
"squad": ["Squad up for success", "Squad goals achieved", "Squad tight bond stronger", "Team work makes", "Squad deeper than"],
|
| 204 |
+
"bestie": ["Partner in crime", "Bestie for life", "Ride or die", "Best friend goals", "Friendship never ends"],
|
| 205 |
+
|
| 206 |
+
# Fashion/Style
|
| 207 |
+
"outfit": ["Outfit on point", "Style game strong", "Fashion forward thinking", "Dressed to impress", "Style is everything"],
|
| 208 |
+
"fashion": ["Fashion is art", "Style over everything", "Runway ready always", "Fashion game strong", "Dressed for success"],
|
| 209 |
+
"style": ["Style is eternal", "Personal style activated", "Fashion forward always", "Style game unmatched", "Dressed to kill"],
|
| 210 |
+
|
| 211 |
+
# Love/Romance
|
| 212 |
+
"love": ["Love is everything", "Heart full of", "Love wins always", "Romance is alive", "Love story continues"],
|
| 213 |
+
"couple": ["Better together always", "Love story goals", "Partner in everything", "Two hearts one", "Couple goals achieved"],
|
| 214 |
+
"date": ["Date night vibes", "Romance is alive", "Perfect evening together", "Love is beautiful", "Hearts aligned perfectly"],
|
| 215 |
+
|
| 216 |
+
# Nature/Outdoors
|
| 217 |
+
"nature": ["Nature is medicine", "Wild and free", "Back to nature", "Earth therapy session", "Natural beauty everywhere"],
|
| 218 |
+
"flowers": ["Bloom where planted", "Fresh as daisy", "Flower power activated", "Natural beauty blooms", "Petals and positivity"],
|
| 219 |
+
"garden": ["Garden therapy session", "Growing something beautiful", "Nature nurtures soul", "Bloom and grow", "Earth magic happening"],
|
| 220 |
+
|
| 221 |
+
# Work/Success
|
| 222 |
+
"work": ["Work hard play harder", "Hustle and heart", "Success is earned", "Grind never stops", "Work mode activated"],
|
| 223 |
+
"success": ["Success tastes sweet", "Hard work pays", "Dream big achieve", "Success is journey", "Winning mindset activated"],
|
| 224 |
+
"business": ["Business mode activated", "Entrepreneur life chosen", "Success is planned", "Building empire daily", "Boss moves only"]
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
# Enhanced cool captions database with complete, meaningful phrases
|
| 228 |
cool_captions = [
|
| 229 |
"Squad goals right here",
|
|
|
|
| 278 |
"Namaste all day long"
|
| 279 |
]
|
| 280 |
|
| 281 |
+
# Find keyword-specific captions
|
| 282 |
+
description_lower = description.lower()
|
| 283 |
+
keyword_specific_captions = []
|
| 284 |
+
|
| 285 |
+
for keyword, captions in keyword_captions.items():
|
| 286 |
+
if keyword in description_lower:
|
| 287 |
+
keyword_specific_captions.extend(captions)
|
| 288 |
+
|
| 289 |
# Generate AI captions if model is available
|
| 290 |
ai_captions = []
|
| 291 |
if generator is not None:
|
|
|
|
| 296 |
ai_captions.append(caption)
|
| 297 |
attempts += 1
|
| 298 |
|
| 299 |
+
# Combine keyword-specific, AI and predefined captions
|
| 300 |
+
# Prioritize keyword-specific captions if found
|
| 301 |
+
if keyword_specific_captions:
|
| 302 |
+
all_captions = keyword_specific_captions + ai_captions + cool_captions
|
| 303 |
+
else:
|
| 304 |
+
all_captions = ai_captions + cool_captions
|
| 305 |
|
| 306 |
# Remove duplicates while preserving order
|
| 307 |
seen = set()
|
|
|
|
| 329 |
if final_caption not in final_captions:
|
| 330 |
final_captions.append(final_caption)
|
| 331 |
|
| 332 |
+
# Format as simple numbered list (removed "Your Instagram Captions" text)
|
| 333 |
result = ""
|
| 334 |
emojis = ["π―", "β‘", "π", "π₯", "π«"]
|
| 335 |
|
|
|
|
| 360 |
font-family: 'Instagram Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
|
| 361 |
}
|
| 362 |
|
| 363 |
+
/* Header styling - Modified to be regular black text */
|
| 364 |
.main-header {
|
| 365 |
text-align: center;
|
| 366 |
+
color: #000000 !important;
|
|
|
|
|
|
|
|
|
|
| 367 |
font-size: 3em;
|
| 368 |
+
font-weight: 400;
|
| 369 |
margin-bottom: 0.5em;
|
|
|
|
| 370 |
padding: 1rem 0;
|
| 371 |
+
background: rgba(255, 255, 255, 0.9);
|
| 372 |
+
border-radius: 15px;
|
| 373 |
+
margin: 1rem;
|
| 374 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
|
| 375 |
}
|
| 376 |
|
| 377 |
.subtitle {
|
|
|
|
| 537 |
title="InstaCap - AI Caption Generator"
|
| 538 |
) as demo:
|
| 539 |
|
| 540 |
+
# Move title to the front and make it regular black
|
| 541 |
+
gr.HTML('<h1 class="main-header">InstaCap β AI Caption Generator</h1>')
|
| 542 |
gr.HTML('<p class="subtitle">Create short, catchy Instagram captions in seconds! Perfect for your social media posts β¨</p>')
|
| 543 |
|
| 544 |
with gr.Row():
|
|
|
|
| 567 |
elem_classes="output-box"
|
| 568 |
)
|
| 569 |
|
| 570 |
+
# Examples are kept in code but not shown in UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
|
| 572 |
# Connect the button to the function
|
| 573 |
generate_btn.click(
|