YUVALON commited on
Commit
8286ccb
Β·
verified Β·
1 Parent(s): 35b12eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +283 -104
app.py CHANGED
@@ -159,122 +159,264 @@ def generate_short_caption(description, max_retries=5):
159
  return ""
160
 
161
  def generate_instagram_captions(description):
162
- """Generate 5 short, catchy Instagram captions (max 5 words each)"""
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": ["Beach vibes only"],
170
- "sea": ["Sea you later"],
171
- "ocean": ["Ocean child wild heart"],
172
- "sand": ["Sandy toes salty kisses"],
173
- "sun": ["Chasing golden hour"],
174
- "sunset": ["Golden hour magic"],
175
- "swimming": ["Making waves today"],
176
- "surfing": ["Riding the waves"],
177
-
178
- # Food related
179
- "food": ["Good food good mood"],
180
- "coffee": ["But first coffee"],
181
- "pizza": ["Pizza my heart"],
182
- "brunch": ["Brunch squad assembled"],
183
-
184
- # Fitness/Health
185
- "gym": ["Sweat now shine later"],
186
- "workout": ["No pain no gain"],
187
- "yoga": ["Peace love and yoga"],
188
- "running": ["Run like you stole"],
189
-
190
- # Travel/Adventure
191
- "travel": ["Wanderlust and city dust"],
192
- "adventure": ["Adventure is out there"],
193
- "hiking": ["Take only pictures"],
194
- "camping": ["Into the wild"],
195
-
196
- # Party/Celebration
197
- "party": ["Party like its"],
198
- "birthday": ["Another year wiser"],
199
- "celebration": ["Cheers to good times"],
200
-
201
- # Friends/Social
202
- "friends": ["Squad goals right here"],
203
- "squad": ["Squad goals achieved"],
204
- "bestie": ["Partner in crime"],
205
-
206
- # Fashion/Style
207
- "outfit": ["Outfit on point"],
208
- "fashion": ["Fashion is art"],
209
- "style": ["Style is eternal"],
210
-
211
- # Love/Romance
212
- "love": ["Love is everything"],
213
- "couple": ["Better together always"],
214
- "date": ["Date night vibes"],
215
-
216
- # Nature/Outdoors
217
- "nature": ["Nature is medicine"],
218
- "flowers": ["Bloom where planted"],
219
- "garden": ["Garden therapy session"],
220
-
221
- # Work/Success
222
- "work": ["Work hard play harder"],
223
- "success": ["Success tastes sweet"],
224
- "business": ["Business mode activated"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  }
226
 
227
- # Find keyword-specific captions
228
- description_lower = description.lower()
229
- keyword_specific_captions = []
230
-
231
- for keyword, captions in keyword_captions.items():
232
- if keyword in description_lower:
233
- keyword_specific_captions.extend(captions)
234
 
235
  # Generate AI captions if model is available
236
  ai_captions = []
237
  if generator is not None:
238
  attempts = 0
239
- while len(ai_captions) < 5 and attempts < 15: # Try to get 5 AI captions
240
  caption = generate_short_caption(description)
241
  if caption and caption not in ai_captions and is_valid_caption(caption):
242
  ai_captions.append(caption)
243
  attempts += 1
244
 
245
- # Combine keyword-specific and AI captions
246
- # Prioritize keyword-specific captions if found
247
- if keyword_specific_captions:
248
- all_captions = keyword_specific_captions + ai_captions
249
- else:
250
- all_captions = ai_captions
251
 
252
  # Remove duplicates while preserving order
253
  seen = set()
254
  unique_captions = []
255
- for caption in all_captions:
256
  if caption not in seen:
257
  seen.add(caption)
258
  unique_captions.append(caption)
259
 
260
- # If we don't have enough captions, create basic fallbacks
261
- if len(unique_captions) < 5:
262
- basic_fallbacks = [
263
- "Picture perfect moment",
264
- "Living my best life",
265
- "Good vibes only",
266
- "Making memories today",
267
- "Life is beautiful"
268
- ]
269
-
270
- for fallback in basic_fallbacks:
271
- if fallback not in unique_captions:
272
- unique_captions.append(fallback)
273
- if len(unique_captions) >= 5:
274
- break
275
-
276
- # Select 5 captions
277
- selected_captions = unique_captions[:5]
278
 
279
  # Ensure each caption is max 5 words and properly formatted
280
  final_captions = []
@@ -283,6 +425,14 @@ def generate_instagram_captions(description):
283
  if len(words) >= 2:
284
  final_captions.append(" ".join(words))
285
 
 
 
 
 
 
 
 
 
286
  # Format as simple numbered list
287
  result = ""
288
  emojis = ["🎯", "⚑", "🌟", "πŸ”₯", "πŸ’«"]
@@ -292,7 +442,7 @@ def generate_instagram_captions(description):
292
 
293
  return result.strip()
294
 
295
- # Simplified Instagram-inspired theme with custom CSS
296
  instagram_css = """
297
  /* Instagram color scheme and modern design */
298
  :root {
@@ -314,19 +464,15 @@ instagram_css = """
314
  font-family: 'Instagram Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
315
  }
316
 
317
- /* Header styling */
318
  .main-header {
319
  text-align: center;
320
- background: linear-gradient(45deg, var(--ig-primary), var(--ig-secondary));
321
- -webkit-background-clip: text;
322
- -webkit-text-fill-color: transparent;
323
- background-clip: text;
324
- color: transparent;
325
  font-size: 3em;
326
  font-weight: 400;
327
  margin-bottom: 0.5em;
328
  padding: 1rem 0;
329
- background-color: rgba(255, 255, 255, 0.9);
330
  border-radius: 15px;
331
  margin: 1rem;
332
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
@@ -407,6 +553,29 @@ instagram_css = """
407
  padding: 1rem !important;
408
  }
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  /* Tips section */
411
  .tips-section {
412
  background: rgba(255, 255, 255, 0.9) !important;
@@ -449,6 +618,16 @@ instagram_css = """
449
  padding: 12px 25px !important;
450
  }
451
  }
 
 
 
 
 
 
 
 
 
 
452
  """
453
 
454
  # Create the Gradio interface
@@ -511,10 +690,10 @@ with gr.Blocks(
511
  <div class="tips-section">
512
  <p>πŸ’‘ <strong>Pro Tips for Better Captions:</strong></p>
513
  <p>🎯 Each caption is maximum 5 words for maximum impact</p>
514
- <p>⚑ Be specific in your description for better AI-generated captions</p>
515
  <p>πŸ“± Copy and paste directly to Instagram, TikTok, or any social platform</p>
516
- <p>πŸ”„ Click generate again for fresh new options</p>
517
- <p>✨ Mix AI-generated captions with trending phrases</p>
518
  </div>
519
  """
520
  )
 
159
  return ""
160
 
161
  def generate_instagram_captions(description):
162
+ """Generate 5 short, catchy Instagram captions (max 5 words each) using cool captions"""
163
  if not description.strip():
164
  return "Please enter a description of your photo! πŸ“Έ"
165
 
166
+ # Massive database of cool modern captions organized by vibe
167
+ cool_captions_db = {
168
+ "general_vibes": [
169
+ "Good vibes only today",
170
+ "Living our best life",
171
+ "Squad goals right here",
172
+ "Making memories with favorites",
173
+ "Caught in the moment",
174
+ "Energy levels unmatched today",
175
+ "Vibes on point always",
176
+ "Good times roll forever",
177
+ "Living for these moments",
178
+ "Making magic happen daily",
179
+ "Good company great memories",
180
+ "Vibes immaculate as always",
181
+ "Energy infectious spread everywhere",
182
+ "Making waves together always",
183
+ "Living life in color",
184
+ "Good vibes attract everything",
185
+ "Caught being absolutely legendary",
186
+ "Creating our own magic",
187
+ "Blessed with the best",
188
+ "Dreams do come true",
189
+ "Forever young at heart",
190
+ "Happiness looks like this"
191
+ ],
192
+ "friendship_squad": [
193
+ "Squad deeper than ocean",
194
+ "Friends like these matter",
195
+ "Squad tight bond stronger",
196
+ "Good energy good people",
197
+ "Squad up for success",
198
+ "Squad goals achieved today",
199
+ "Team work makes dreams",
200
+ "Squad deeper than family",
201
+ "Friends forever and always",
202
+ "Squad goals right here",
203
+ "Squad assembled ready always",
204
+ "Squad till the end",
205
+ "Squad stronger than ever",
206
+ "Squad vibes unmatched today",
207
+ "Squad goals achieved finally",
208
+ "Squad energy off charts",
209
+ "Squad love runs deep",
210
+ "Squad goals never ending",
211
+ "Squad till we die",
212
+ "Squad brings out best"
213
+ ],
214
+ "confident_boss": [
215
+ "Boss moves only today",
216
+ "Confidence level maximum reached",
217
+ "Main character energy activated",
218
+ "That girl energy today",
219
+ "Boss babe vibes only",
220
+ "Confidence is my outfit",
221
+ "Serving looks and attitude",
222
+ "Boss energy never fades",
223
+ "Confidence on ten always",
224
+ "Boss mode permanently on",
225
+ "Confidence through the roof",
226
+ "Boss vibes all day",
227
+ "Confidence is my superpower",
228
+ "Boss lady energy strong",
229
+ "Confidence level expert mode",
230
+ "Boss moves make history",
231
+ "Confidence speaks for itself",
232
+ "Boss energy infectious spreading",
233
+ "Confidence is my weapon",
234
+ "Boss vibes never off"
235
+ ],
236
+ "aesthetic_mood": [
237
+ "Aesthetic vibes only today",
238
+ "Mood captured perfectly here",
239
+ "Aesthetic game too strong",
240
+ "Vibes aesthetic perfection achieved",
241
+ "Mood board inspiration daily",
242
+ "Aesthetic energy flowing freely",
243
+ "Mood ring says happy",
244
+ "Aesthetic goals achieved today",
245
+ "Mood boost successfully delivered",
246
+ "Aesthetic vibes never ending",
247
+ "Mood elevated to maximum",
248
+ "Aesthetic perfection in progress",
249
+ "Mood lighting hits different",
250
+ "Aesthetic energy through roof",
251
+ "Mood captured in pixels",
252
+ "Aesthetic vibes permanently on",
253
+ "Mood board worthy moment",
254
+ "Aesthetic goals finally achieved",
255
+ "Mood enhanced by beauty",
256
+ "Aesthetic vibes multiply daily"
257
+ ],
258
+ "fun_playful": [
259
+ "Chaos and we prosper",
260
+ "Weekend warriors in action",
261
+ "Sunshine mixed with chaos",
262
+ "Adventure awaits us always",
263
+ "Mischief managed successfully today",
264
+ "Chaos coordinator reporting duty",
265
+ "Fun police cant stop",
266
+ "Chaos with a purpose",
267
+ "Mischief level expert achieved",
268
+ "Chaos brings us together",
269
+ "Fun mode permanently activated",
270
+ "Chaos creates best memories",
271
+ "Mischief makes life interesting",
272
+ "Chaos with good intentions",
273
+ "Fun times multiply exponentially",
274
+ "Chaos theory in action",
275
+ "Mischief planned and executed",
276
+ "Chaos brings out creativity",
277
+ "Fun vibes spreading everywhere",
278
+ "Chaos with positive energy"
279
+ ],
280
+ "motivational_success": [
281
+ "Grinding until dreams reality",
282
+ "Success tastes so sweet",
283
+ "Hustle hard dream bigger",
284
+ "Grinding never stops here",
285
+ "Success is only option",
286
+ "Hustle mode permanently on",
287
+ "Grinding toward bigger goals",
288
+ "Success follows consistent effort",
289
+ "Hustle beats talent consistently",
290
+ "Grinding creates diamond pressure",
291
+ "Success is earned daily",
292
+ "Hustle culture lifestyle choice",
293
+ "Grinding through every obstacle",
294
+ "Success mindset never rests",
295
+ "Hustle harder than yesterday",
296
+ "Grinding until goals achieved",
297
+ "Success requires relentless pursuit",
298
+ "Hustle creates unstoppable momentum",
299
+ "Grinding builds character strength",
300
+ "Success is inevitable outcome"
301
+ ],
302
+ "chill_relaxed": [
303
+ "Zen mode activated today",
304
+ "Peace love and positivity",
305
+ "Chill vibes only please",
306
+ "Zen energy flowing freely",
307
+ "Peace found in simplicity",
308
+ "Chill mode permanently on",
309
+ "Zen master in training",
310
+ "Peace within creates harmony",
311
+ "Chill vibes multiply naturally",
312
+ "Zen state of mind",
313
+ "Peace radiates from within",
314
+ "Chill energy infectious spreading",
315
+ "Zen garden of thoughts",
316
+ "Peace is my superpower",
317
+ "Chill vibes heal everything",
318
+ "Zen moments create clarity",
319
+ "Peace found in present",
320
+ "Chill mode healing process",
321
+ "Zen energy restores balance",
322
+ "Peace multiplies when shared"
323
+ ],
324
+ "trendy_gen_z": [
325
+ "No cap this slaps",
326
+ "Periodt end of discussion",
327
+ "This hits different though",
328
+ "Absolutely serving looks today",
329
+ "This is it chief",
330
+ "We understood the assignment",
331
+ "This absolutely sends me",
332
+ "Living rent free here",
333
+ "This is the vibe",
334
+ "Absolutely no skips today",
335
+ "This is so valid",
336
+ "We really did that",
337
+ "This is the moment",
338
+ "Absolutely understood assignment perfectly",
339
+ "This hits every time",
340
+ "We said what said",
341
+ "This is peak content",
342
+ "Absolutely no notes needed",
343
+ "This is the energy",
344
+ "We chose violence today"
345
+ ],
346
+ "night_out": [
347
+ "Night out squad assembled",
348
+ "Party mode fully activated",
349
+ "Night vibes hit different",
350
+ "Party till sunrise today",
351
+ "Night out energy unmatched",
352
+ "Party like there tomorrow",
353
+ "Night out goals achieved",
354
+ "Party mode never ends",
355
+ "Night vibes absolutely immaculate",
356
+ "Party energy through roof",
357
+ "Night out memories made",
358
+ "Party until legs hurt",
359
+ "Night out squad goals",
360
+ "Party mode is lifestyle",
361
+ "Night vibes multiply exponentially",
362
+ "Party energy infectious spreading",
363
+ "Night out therapy session",
364
+ "Party mode permanently activated",
365
+ "Night vibes heal everything",
366
+ "Party like world watching"
367
+ ],
368
+ "self_love": [
369
+ "Self love Sunday activated",
370
+ "Main character energy strong",
371
+ "Self care Sunday vibes",
372
+ "Self love looks good",
373
+ "Main character moment captured",
374
+ "Self care never optional",
375
+ "Self love is superpower",
376
+ "Main character energy activated",
377
+ "Self care Sunday ritual",
378
+ "Self love journey continues",
379
+ "Main character vibes only",
380
+ "Self care is healthcare",
381
+ "Self love wins always",
382
+ "Main character development complete",
383
+ "Self care Sunday success",
384
+ "Self love radiates outward",
385
+ "Main character energy infectious",
386
+ "Self care heals everything",
387
+ "Self love multiplies daily",
388
+ "Main character story continues"
389
+ ]
390
  }
391
 
392
+ # Flatten all cool captions into one big list
393
+ all_cool_captions = []
394
+ for category, captions in cool_captions_db.items():
395
+ all_cool_captions.extend(captions)
 
 
 
396
 
397
  # Generate AI captions if model is available
398
  ai_captions = []
399
  if generator is not None:
400
  attempts = 0
401
+ while len(ai_captions) < 2 and attempts < 10: # Try to get at least 2 good AI captions
402
  caption = generate_short_caption(description)
403
  if caption and caption not in ai_captions and is_valid_caption(caption):
404
  ai_captions.append(caption)
405
  attempts += 1
406
 
407
+ # Combine AI and predefined cool captions
408
+ combined_captions = ai_captions + all_cool_captions
 
 
 
 
409
 
410
  # Remove duplicates while preserving order
411
  seen = set()
412
  unique_captions = []
413
+ for caption in combined_captions:
414
  if caption not in seen:
415
  seen.add(caption)
416
  unique_captions.append(caption)
417
 
418
+ # Select 5 random captions
419
+ selected_captions = random.sample(unique_captions, min(5, len(unique_captions)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
 
421
  # Ensure each caption is max 5 words and properly formatted
422
  final_captions = []
 
425
  if len(words) >= 2:
426
  final_captions.append(" ".join(words))
427
 
428
+ # Fill with defaults if needed
429
+ while len(final_captions) < 5:
430
+ fallback = random.choice(all_cool_captions)
431
+ words = fallback.split()[:5]
432
+ final_caption = " ".join(words)
433
+ if final_caption not in final_captions:
434
+ final_captions.append(final_caption)
435
+
436
  # Format as simple numbered list
437
  result = ""
438
  emojis = ["🎯", "⚑", "🌟", "πŸ”₯", "πŸ’«"]
 
442
 
443
  return result.strip()
444
 
445
+ # Enhanced Instagram-inspired theme with custom CSS
446
  instagram_css = """
447
  /* Instagram color scheme and modern design */
448
  :root {
 
464
  font-family: 'Instagram Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
465
  }
466
 
467
+ /* Header styling - Modified to be regular black text */
468
  .main-header {
469
  text-align: center;
470
+ color: #000000 !important;
 
 
 
 
471
  font-size: 3em;
472
  font-weight: 400;
473
  margin-bottom: 0.5em;
474
  padding: 1rem 0;
475
+ background: rgba(255, 255, 255, 0.9);
476
  border-radius: 15px;
477
  margin: 1rem;
478
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
 
553
  padding: 1rem !important;
554
  }
555
 
556
+ /* Examples styling */
557
+ .gr-examples {
558
+ background: rgba(255, 255, 255, 0.8) !important;
559
+ border-radius: 15px !important;
560
+ padding: 1rem !important;
561
+ margin-top: 1rem !important;
562
+ }
563
+
564
+ .gr-examples .gr-button {
565
+ background: linear-gradient(45deg, var(--ig-tertiary), var(--ig-quaternary)) !important;
566
+ border: none !important;
567
+ border-radius: 10px !important;
568
+ color: white !important;
569
+ margin: 0.25rem !important;
570
+ transition: all 0.3s ease !important;
571
+ font-weight: 600 !important;
572
+ }
573
+
574
+ .gr-examples .gr-button:hover {
575
+ transform: translateY(-2px) !important;
576
+ box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important;
577
+ }
578
+
579
  /* Tips section */
580
  .tips-section {
581
  background: rgba(255, 255, 255, 0.9) !important;
 
618
  padding: 12px 25px !important;
619
  }
620
  }
621
+
622
+ /* Loading animation */
623
+ @keyframes pulse {
624
+ 0%, 100% { opacity: 1; }
625
+ 50% { opacity: 0.5; }
626
+ }
627
+
628
+ .loading {
629
+ animation: pulse 2s infinite;
630
+ }
631
  """
632
 
633
  # Create the Gradio interface
 
690
  <div class="tips-section">
691
  <p>πŸ’‘ <strong>Pro Tips for Better Captions:</strong></p>
692
  <p>🎯 Each caption is maximum 5 words for maximum impact</p>
693
+ <p>⚑ Get fresh trendy captions every time you generate</p>
694
  <p>πŸ“± Copy and paste directly to Instagram, TikTok, or any social platform</p>
695
+ <p>πŸ”„ Click generate again for completely new cool options</p>
696
+ <p>✨ Mix of AI-generated and trending cool captions</p>
697
  </div>
698
  """
699
  )