jasonlawAI79 commited on
Commit
2338961
Β·
verified Β·
1 Parent(s): 9c19a7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +374 -17
app.py CHANGED
@@ -1,4 +1,15 @@
1
- # Quick debugging - add this right after the hashtag generation in your app.py
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def generate_smart_hashtags(lyrics: str, song_title: str, artist_name: str, mood: str, themes: list, platform: str) -> str:
4
  """Generate smart, relevant hashtags based on lyrics analysis and platform limits"""
@@ -52,7 +63,7 @@ def generate_smart_hashtags(lyrics: str, song_title: str, artist_name: str, mood
52
  # Build hashtag list
53
  hashtags = []
54
 
55
- # Add platform-specific base tags (limit to 3 for more room)
56
  if platform in trending_base:
57
  hashtags.extend(trending_base[platform][:3])
58
 
@@ -110,23 +121,369 @@ def generate_smart_hashtags(lyrics: str, song_title: str, artist_name: str, mood
110
  limit = limits.get(platform, 10)
111
  final_hashtags = unique_hashtags[:limit]
112
 
113
- # DEBUG: Print the count for testing
114
- print(f"Platform: {platform}, Generated: {len(final_hashtags)} hashtags, Limit: {limit}")
115
- print(f"Hashtags: {final_hashtags}")
116
-
117
  # Format with # symbol
118
  return ' '.join(f'#{tag}' for tag in final_hashtags)
119
 
120
- # Test function - you can run this to see what it generates
121
- def test_hashtags():
122
- test_lyrics = "Rock energy, driving drums, guitar, love, life, time"
123
- result = generate_smart_hashtags(test_lyrics, "Test Song", "", "uplifting", ["love", "life"], "youtube")
124
- print(f"YouTube result: {result}")
125
- print(f"Count: {len(result.split())}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
- minds_result = generate_smart_hashtags(test_lyrics, "Test Song", "", "uplifting", ["love", "life"], "minds")
128
- print(f"Minds result: {minds_result}")
129
- print(f"Count: {len(minds_result.split())}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- # Run the test
132
- test_hashtags()
 
1
+ import gradio as gr
2
+ import os
3
+ from typing import Dict
4
+ import re
5
+
6
+ # Try to import Modal for calling deployed functions
7
+ try:
8
+ from modal import Function
9
+ MODAL_AVAILABLE = True
10
+ except ImportError:
11
+ MODAL_AVAILABLE = False
12
+ print("Modal not available - using fallback generation only")
13
 
14
  def generate_smart_hashtags(lyrics: str, song_title: str, artist_name: str, mood: str, themes: list, platform: str) -> str:
15
  """Generate smart, relevant hashtags based on lyrics analysis and platform limits"""
 
63
  # Build hashtag list
64
  hashtags = []
65
 
66
+ # Add platform-specific base tags (reduced for space)
67
  if platform in trending_base:
68
  hashtags.extend(trending_base[platform][:3])
69
 
 
121
  limit = limits.get(platform, 10)
122
  final_hashtags = unique_hashtags[:limit]
123
 
 
 
 
 
124
  # Format with # symbol
125
  return ' '.join(f'#{tag}' for tag in final_hashtags)
126
 
127
+ def call_modal_ai_generation(lyrics: str, artist_name: str, song_title: str) -> Dict[str, str]:
128
+ """Call the deployed Modal AI generation function"""
129
+ try:
130
+ # Look up the deployed Modal function
131
+ generate_ai_content = Function.lookup("content-creation-backend", "generate_content_with_llm")
132
+ result = generate_ai_content.remote(lyrics, artist_name, song_title)
133
+ return result
134
+ except Exception as e:
135
+ return {"error": f"Modal AI generation failed: {str(e)}"}
136
+
137
+ def call_modal_template_generation(lyrics: str, artist_name: str, song_title: str) -> Dict[str, str]:
138
+ """Call the deployed Modal template generation function"""
139
+ try:
140
+ # Look up the deployed Modal function
141
+ generate_template_content = Function.lookup("content-creation-backend", "generate_fallback_content")
142
+ result = generate_template_content.remote(lyrics, artist_name, song_title)
143
+ return result
144
+ except Exception as e:
145
+ return {"error": f"Modal template generation failed: {str(e)}"}
146
+
147
+ def local_fallback_content(lyrics: str, artist_name: str, song_title: str) -> Dict[str, str]:
148
+ """Local fallback content generation if Modal is unavailable"""
149
+
150
+ # Extract key words and themes from lyrics
151
+ words = re.findall(r'\b[a-zA-Z]{4,}\b', lyrics.lower())
152
+ common_words = {'love', 'heart', 'time', 'life', 'feel', 'know', 'want', 'need', 'like', 'come', 'back', 'away', 'never', 'always', 'forever', 'dream', 'night', 'freedom'}
153
+ themes = [word for word in set(words) if word in common_words]
154
+
155
+ # Determine mood based on common words
156
+ positive_words = {'love', 'happy', 'joy', 'hope', 'dream', 'light', 'beautiful', 'amazing', 'bright', 'inspiring'}
157
+ sad_words = {'cry', 'tear', 'pain', 'hurt', 'lost', 'lonely', 'dark', 'goodbye', 'broken'}
158
+
159
+ mood = "uplifting"
160
+ if any(word in lyrics.lower() for word in sad_words):
161
+ mood = "emotional"
162
+ elif any(word in lyrics.lower() for word in positive_words):
163
+ mood = "inspiring"
164
+
165
+ # Handle optional artist name
166
+ artist_display = artist_name if artist_name.strip() else "Anonymous Artist"
167
+ by_artist = f" - {artist_display}" if artist_name.strip() else ""
168
+
169
+ # Generate smart hashtags for each platform
170
+ youtube_hashtags = generate_smart_hashtags(lyrics, song_title, artist_name, mood, themes, 'youtube')
171
+ twitter_hashtags = generate_smart_hashtags(lyrics, song_title, artist_name, mood, themes, 'twitter')
172
+ facebook_hashtags = generate_smart_hashtags(lyrics, song_title, artist_name, mood, themes, 'facebook')
173
+ instagram_hashtags = generate_smart_hashtags(lyrics, song_title, artist_name, mood, themes, 'instagram')
174
+ minds_hashtags = generate_smart_hashtags(lyrics, song_title, artist_name, mood, themes, 'minds')
175
+ gab_hashtags = generate_smart_hashtags(lyrics, song_title, artist_name, mood, themes, 'gab')
176
+
177
+ if artist_name.strip():
178
+ # Content with artist name
179
+ youtube_desc = f"""🎡 {song_title}{by_artist} 🎡
180
+
181
+ Experience this latest music video! This {mood} track explores themes of {', '.join(themes[:3]) if themes else 'love and life'}.
182
+
183
+ 🎬 Watch the full music video above
184
+ πŸ’Ώ Stream on all platforms
185
+ πŸ”” Subscribe for more music videos
186
+ οΏ½οΏ½ Like if you enjoyed this track
187
+
188
+ πŸ“ LYRICS:
189
+ {lyrics}
190
+
191
+ {youtube_hashtags}"""
192
+
193
+ twitter_post = f"🎡 NEW MUSIC VIDEO: '{song_title}'{by_artist} is here! This {mood} track will give you all the feels πŸ’«\n\n🎬 Watch: [Link]\n\n{twitter_hashtags}"
194
+
195
+ facebook_post = f"""🎡 MUSIC VIDEO PREMIERE 🎡
196
+
197
+ New music video for '{song_title}'{by_artist} just dropped!
198
+
199
+ This {mood} track captures the essence of {', '.join(themes[:2]) if themes else 'human emotion'} in a beautiful way. The visuals perfectly complement the powerful lyrics.
200
+
201
+ 🎬 Watch the full video now!
202
+ πŸ’¬ Let us know what you think in the comments
203
+ πŸ”„ Share with friends who love good music
204
+
205
+ {facebook_hashtags}"""
206
+
207
+ instagram_post = f"""🎡✨ '{song_title}' Official Music Video is LIVE! ✨🎡
208
+
209
+ {artist_display} delivers another {mood} masterpiece that speaks to the soul πŸ’«
210
+
211
+ 🎬 Full video in bio
212
+ πŸ’­ What's your favorite lyric? Comment below!
213
+
214
+ {instagram_hashtags}"""
215
+
216
+ minds_post = f"""🎡 New Music Alert!
217
+
218
+ {artist_display} - '{song_title}' Official Music Video
219
+
220
+ This {mood} track showcases incredible artistry and meaningful lyrics. Independent artists like {artist_display} are creating the future of music.
221
+
222
+ Support independent music and check out this latest release!
223
+
224
+ {minds_hashtags}"""
225
+
226
+ gab_post = f"""New Music Video Drop!
227
+
228
+ '{song_title}'{by_artist}
229
+
230
+ Real music with real meaning. This {mood} track reminds us why authentic artistry matters in today's world.
231
+
232
+ Give it a listen and support independent creators!
233
+
234
+ {gab_hashtags}"""
235
+
236
+ else:
237
+ # Content without artist name (anonymous)
238
+ youtube_desc = f"""🎡 {song_title} 🎡
239
+
240
+ Experience this captivating music video! This {mood} track explores themes of {', '.join(themes[:3]) if themes else 'love and life'}.
241
+
242
+ 🎬 Watch the full music video above
243
+ πŸ’Ώ Available on all streaming platforms
244
+ πŸ”” Subscribe for more amazing music videos
245
+ πŸ‘ Like if this track moved you
246
+
247
+ πŸ“ LYRICS:
248
+ {lyrics}
249
+
250
+ {youtube_hashtags}"""
251
+
252
+ twitter_post = f"🎡 NEW MUSIC VIDEO: '{song_title}' is here! This {mood} track will give you all the feels πŸ’«\n\n🎬 Watch: [Link]\n\n{twitter_hashtags}"
253
+
254
+ facebook_post = f"""🎡 MUSIC VIDEO PREMIERE 🎡
255
+
256
+ '{song_title}' official music video just dropped!
257
+
258
+ This {mood} track captures the essence of {', '.join(themes[:2]) if themes else 'human emotion'} in a beautiful way. The visuals perfectly complement the powerful lyrics.
259
+
260
+ 🎬 Watch the full video now!
261
+ πŸ’¬ Let us know what you think in the comments
262
+ πŸ”„ Share with friends who love good music
263
+
264
+ {facebook_hashtags}"""
265
+
266
+ instagram_post = f"""🎡✨ '{song_title}' Official Music Video is LIVE! ✨🎡
267
+
268
+ Another {mood} masterpiece that speaks to the soul πŸ’«
269
+
270
+ 🎬 Full video in bio
271
+ πŸ’­ What's your favorite lyric? Comment below!
272
+
273
+ {instagram_hashtags}"""
274
+
275
+ minds_post = f"""🎡 New Music Alert!
276
+
277
+ '{song_title}' Official Music Video
278
+
279
+ This {mood} track showcases incredible artistry and meaningful lyrics. Independent music continues to push creative boundaries.
280
+
281
+ Support independent music and check out this latest release!
282
+
283
+ {minds_hashtags}"""
284
+
285
+ gab_post = f"""New Music Video Drop!
286
+
287
+ '{song_title}'
288
+
289
+ Real music with real meaning. This {mood} track reminds us why authentic artistry matters in today's world.
290
+
291
+ Give it a listen and support independent creators!
292
+
293
+ {gab_hashtags}"""
294
+
295
+ return {
296
+ 'youtube': youtube_desc,
297
+ 'twitter': twitter_post,
298
+ 'facebook': facebook_post,
299
+ 'instagram': instagram_post,
300
+ 'minds': minds_post,
301
+ 'gab': gab_post
302
+ }
303
+
304
+ # Main Gradio interface function
305
+ def create_content(lyrics: str, artist_name: str, song_title: str, use_ai: bool = True):
306
+ """Main function to create content"""
307
+
308
+ if not lyrics.strip() or not song_title.strip():
309
+ return "❌ Please fill in the required fields: lyrics and song title. Artist name is optional."
310
+
311
+ try:
312
+ content = None
313
+ generation_method = "Unknown"
314
+
315
+ if use_ai and MODAL_AVAILABLE:
316
+ # Try AI generation via Modal first
317
+ content = call_modal_ai_generation(lyrics, artist_name, song_title)
318
+ if "error" not in content:
319
+ generation_method = "πŸ€– AI Generation (Modal GPU)"
320
+ else:
321
+ # Fallback to Modal template generation
322
+ content = call_modal_template_generation(lyrics, artist_name, song_title)
323
+ generation_method = "πŸ“ Template Generation (Modal)"
324
+
325
+ elif MODAL_AVAILABLE:
326
+ # Use Modal template generation
327
+ content = call_modal_template_generation(lyrics, artist_name, song_title)
328
+ generation_method = "πŸ“ Template Generation (Modal)"
329
+
330
+ if content is None or "error" in content:
331
+ # Final fallback to local generation
332
+ content = local_fallback_content(lyrics, artist_name, song_title)
333
+ generation_method = "πŸ“ Local Template Generation"
334
+
335
+ # Format output for display
336
+ artist_display = artist_name if artist_name.strip() else "Anonymous"
337
+ output = f"""
338
+ # 🎡 Content Generated for '{song_title}' by {artist_display}
339
+ *Generated using: {generation_method}*
340
+
341
+ ## πŸ“Ί YouTube Description:
342
+ {content.get('youtube', 'Generation failed')}
343
+
344
+ ---
345
+
346
+ ## 🐦 Twitter/X Post:
347
+ {content.get('twitter', 'Generation failed')}
348
+
349
+ ---
350
+
351
+ ## πŸ“˜ Facebook Post:
352
+ {content.get('facebook', 'Generation failed')}
353
+
354
+ ---
355
+
356
+ ## πŸ“Έ Instagram Caption:
357
+ {content.get('instagram', 'Generation failed')}
358
+
359
+ ---
360
+
361
+ ## 🧠 Minds Post:
362
+ {content.get('minds', 'Generation failed')}
363
+
364
+ ---
365
+
366
+ ## πŸ’¬ Gab Post:
367
+ {content.get('gab', 'Generation failed')}
368
+
369
+ ---
370
+
371
+ ### 🎯 AI Agent Features Used:
372
+ βœ… **Autonomous Lyric Analysis** - Extracted themes and mood automatically
373
+ βœ… **Multi-Platform Optimization** - Generated platform-specific content
374
+ βœ… **Smart Hashtag Generation** - Created relevant hashtags for each platform
375
+ βœ… **Anonymous Release Support** - Adapted content for optional artist name
376
+ βœ… **Mood Detection** - Determined emotional tone from lyrics
377
+ βœ… **Content Orchestration** - Coordinated complete social media campaign
378
+ """
379
+ return output
380
+
381
+ except Exception as e:
382
+ # Final fallback to local generation
383
+ content = local_fallback_content(lyrics, artist_name, song_title)
384
+
385
+ artist_display = artist_name if artist_name.strip() else "Anonymous"
386
+ output = f"""
387
+ # 🎡 Content Generated for '{song_title}' by {artist_display}
388
+ *Generated using: πŸ“ Local Template Generation (Fallback)*
389
+
390
+ ## πŸ“Ί YouTube Description:
391
+ {content.get('youtube', 'Generation failed')}
392
+
393
+ ---
394
+
395
+ ## 🐦 Twitter/X Post:
396
+ {content.get('twitter', 'Generation failed')}
397
+
398
+ ---
399
+
400
+ ## πŸ“˜ Facebook Post:
401
+ {content.get('facebook', 'Generation failed')}
402
+
403
+ ---
404
+
405
+ ## πŸ“Έ Instagram Caption:
406
+ {content.get('instagram', 'Generation failed')}
407
+
408
+ ---
409
+
410
+ ## 🧠 Minds Post:
411
+ {content.get('minds', 'Generation failed')}
412
+
413
+ ---
414
+
415
+ ## πŸ’¬ Gab Post:
416
+ {content.get('gab', 'Generation failed')}
417
+ """
418
+ return output
419
+
420
+ # Create Gradio interface
421
+ interface = gr.Interface(
422
+ fn=create_content,
423
+ inputs=[
424
+ gr.Textbox(
425
+ lines=10,
426
+ placeholder="Paste your song lyrics here...",
427
+ label="🎡 Song Lyrics",
428
+ info="Enter the complete lyrics of your song"
429
+ ),
430
+ gr.Textbox(
431
+ placeholder="Artist Name (Optional)",
432
+ label="🎀 Artist Name",
433
+ info="Leave blank for anonymous releases"
434
+ ),
435
+ gr.Textbox(
436
+ placeholder="Song Title",
437
+ label="🎡 Song Title",
438
+ info="The title of your song"
439
+ ),
440
+ gr.Checkbox(
441
+ label="πŸ€– Use AI Generation",
442
+ value=True,
443
+ info="Uses Modal GPU for AI generation (fallback to templates if unavailable)"
444
+ )
445
+ ],
446
+ outputs=gr.Markdown(label="πŸ“± Generated Social Media Content"),
447
+ title="🎡 YouTube Music Video Content Creator Agent 🎬",
448
+ description=f"""
449
+ **Transform your song lyrics into compelling social media content using AI agents!**
450
+
451
+ This autonomous AI agent creates complete social media campaigns:
452
+ - βœ… YouTube video descriptions with SEO optimization
453
+ - βœ… Twitter/X posts with hashtags
454
+ - βœ… Facebook promotional posts
455
+ - βœ… Instagram captions with trending hashtags
456
+ - βœ… Minds platform posts
457
+ - βœ… Gab social posts
458
+
459
+ **πŸ€– AI Agent Capabilities:**
460
+ - Autonomous lyric analysis and theme extraction
461
+ - Multi-platform content orchestration
462
+ - Smart hashtag generation for each platform
463
+ - Anonymous release support (artist name optional)
464
+ - Mood detection and content adaptation
465
+
466
+ **πŸ’» Powered by Modal:** {"βœ… Connected to Modal GPU backend" if MODAL_AVAILABLE else "❌ Using local fallback (Modal unavailable)"}
467
 
468
+ Perfect for music creators who want professional social media content without the manual work!
469
+ """,
470
+ theme=gr.themes.Soft(),
471
+ examples=[
472
+ [
473
+ "Here's an example with some sample lyrics\nAbout dreams and aspirations\nReaching for the stars tonight\nNothing's gonna stop this fight\nWe'll keep on climbing higher\nUntil we touch the sky",
474
+ "", # Empty artist name for anonymous example
475
+ "Dreams Tonight",
476
+ True
477
+ ],
478
+ [
479
+ "Love is in the air tonight\nHearts beating as one\nDancing under moonlight\nUntil the morning sun\nThis feeling never ends\nLove conquers all",
480
+ "Romantic Vibes",
481
+ "Moonlight Dance",
482
+ False
483
+ ]
484
+ ],
485
+ cache_examples=False
486
+ )
487
 
488
+ if __name__ == "__main__":
489
+ interface.launch()