cryogenic22 commited on
Commit
8aa5d78
Β·
verified Β·
1 Parent(s): 8558fe9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -113
app.py CHANGED
@@ -249,48 +249,36 @@ class ContentGenerator:
249
  log_message(f"❌ Image generation failed: {str(e)}", "error")
250
  raise
251
 
252
- def generate_audio(self, tradition, theme):
253
  """Generate background music using MusicGen"""
254
  try:
255
  log_message("🎡 Starting audio generation")
256
 
257
- music_prompts = {
258
- "Buddhism": {
259
- "Inner Peace": "Tibetan singing bowls and gentle bells with peaceful ambient drones, meditative and serene",
260
- "Mindfulness": "Zen flute melodies with soft water sounds, creating a mindful atmosphere",
261
- "default": "Meditation bells with nature sounds, peaceful and calming"
262
- },
263
- "Hinduism": {
264
- "Devotion": "Indian bansuri flute with gentle tabla rhythms, creating a devotional atmosphere",
265
- "Wisdom": "Gentle sitar melodies with peaceful tanpura drone",
266
- "default": "Sanskrit chants with soft instrumentation, peaceful and meditative"
267
- },
268
- "Modern Spirituality": {
269
- "Awareness": "Ambient synthesizer with crystal bowls, creating a modern meditative atmosphere",
270
- "Growth": "Uplifting piano melodies with gentle ambient pads",
271
- "default": "Modern meditation music with nature sounds and gentle electronics"
272
- },
273
- "default": {
274
- "default": "Peaceful ambient music with gentle bells and subtle harmonies"
275
- }
276
- }
277
-
278
  tradition_prompts = music_prompts.get(tradition, music_prompts["default"])
279
  prompt = tradition_prompts.get(theme, tradition_prompts["default"])
280
 
 
281
  output = self.replicate_client.run(
282
- "meta/musicgen:671ac645ce5e552cc63a54a2bbff63fcf798043055d2dac5fc9e36a837eedcfb", # Updated model version
283
  input={
284
  "prompt": prompt,
285
- "model_version": "stereo-large", # Using stereo large model
286
  "output_format": "mp3",
287
  "normalization_strategy": "peak",
288
- "duration": 15 # Length in seconds
289
  }
290
  )
291
 
 
 
 
 
 
 
 
 
292
  log_message("✨ Audio generated successfully")
293
- return output
294
  except Exception as e:
295
  log_message(f"❌ Audio generation failed: {str(e)}", "error")
296
  raise
@@ -417,93 +405,28 @@ def main():
417
  st.subheader("Generated Content Details")
418
  st.json(st.session_state.generated_content)
419
 
420
- with tab2:
421
- st.title("Instagram Preview")
422
-
423
- if all([st.session_state.generated_content,
424
- st.session_state.generated_image,
425
- st.session_state.generated_audio]):
426
-
427
- col1, col2 = st.columns([2, 1])
428
-
429
- with col1:
430
- # Display generated image with quote overlay
431
- st.image(st.session_state.generated_image, use_column_width=True)
432
-
433
- # Quote overlay
434
- quote = st.session_state.generated_content
435
- st.markdown(f"""
436
- <div style='
437
- background-color: rgba(255,255,255,0.8);
438
- padding: 20px;
439
- border-radius: 10px;
440
- margin: 10px 0;
441
- text-align: center;
442
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
443
- '>
444
- <h2 style='font-size: 24px; margin-bottom: 10px;'>{quote['text']}</h2>
445
- <p style='font-style: italic;'>- {quote['author']}</p>
446
- </div>
447
- """, unsafe_allow_html=True)
448
-
449
- with col2:
450
- # Audio preview
451
- st.subheader("🎡 Background Music")
452
- if st.session_state.generated_audio:
453
- st.audio(st.session_state.generated_audio, format='audio/mp3')
454
-
455
- # Caption generation
456
- st.subheader("πŸ“ Caption")
457
- hashtags = generate_hashtags(
458
- quote['tradition'],
459
- quote.get('theme', 'Wisdom')
460
- )
461
- caption = f"""✨ Wisdom from {quote['tradition']} ✨
462
-
463
- "{quote['text']}"
464
- - {quote['author']}
465
-
466
- Theme: {quote.get('theme', 'Wisdom')}
467
-
468
- {' '.join(hashtags)}"""
469
-
470
- st.text_area("Instagram Caption", caption, height=200)
471
-
472
- # Download buttons
473
- col1, col2 = st.columns(2)
474
- with col1:
475
- if st.session_state.generated_image:
476
- image_data = requests.get(st.session_state.generated_image).content
477
- st.download_button(
478
- "πŸ“₯ Download Image",
479
- data=image_data,
480
- file_name="spiritual_quote.jpg",
481
- mime="image/jpeg"
482
- )
483
-
484
- with col2:
485
- if st.session_state.generated_audio:
486
- audio_data = requests.get(st.session_state.generated_audio).content
487
- st.download_button(
488
- "πŸ“₯ Download Audio",
489
- data=audio_data,
490
- file_name="background_music.mp3",
491
- mime="audio/mp3"
492
- )
493
-
494
- # Posting tips
495
- st.markdown("""
496
- ### πŸ“± Posting Tips
497
- 1. Download the image and audio
498
- 2. Combine them using any video editor
499
- 3. Copy the generated caption
500
- 4. Best posting times: 8-10 AM or 6-8 PM
501
- 5. Engage with your audience about the quote's meaning
502
- 6. Use Instagram's Reels for better reach
503
- """)
504
-
505
- else:
506
- st.info("Generate content first to see the Instagram preview")
507
 
508
  with tab3:
509
  display_debug_logs()
 
249
  log_message(f"❌ Image generation failed: {str(e)}", "error")
250
  raise
251
 
252
+ def generate_audio(self, tradition, theme):
253
  """Generate background music using MusicGen"""
254
  try:
255
  log_message("🎡 Starting audio generation")
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  tradition_prompts = music_prompts.get(tradition, music_prompts["default"])
258
  prompt = tradition_prompts.get(theme, tradition_prompts["default"])
259
 
260
+ # Get the audio file URL
261
  output = self.replicate_client.run(
262
+ "meta/musicgen:671ac645ce5e552cc63a54a2bbff63fcf798043055d2dac5fc9e36a837eedcfb",
263
  input={
264
  "prompt": prompt,
265
+ "model_version": "stereo-large",
266
  "output_format": "mp3",
267
  "normalization_strategy": "peak",
268
+ "duration": 15
269
  }
270
  )
271
 
272
+ # Convert FileOutput to URL if needed
273
+ if hasattr(output, 'url'):
274
+ audio_url = output.url
275
+ elif isinstance(output, str):
276
+ audio_url = output
277
+ else:
278
+ audio_url = str(output)
279
+
280
  log_message("✨ Audio generated successfully")
281
+ return audio_url
282
  except Exception as e:
283
  log_message(f"❌ Audio generation failed: {str(e)}", "error")
284
  raise
 
405
  st.subheader("Generated Content Details")
406
  st.json(st.session_state.generated_content)
407
 
408
+ with col2:
409
+ # Audio preview
410
+ st.subheader("🎡 Background Music")
411
+ if st.session_state.generated_audio:
412
+ try:
413
+ # Get audio data from URL
414
+ audio_response = requests.get(st.session_state.generated_audio)
415
+ if audio_response.status_code == 200:
416
+ # Create audio player
417
+ st.audio(audio_response.content, format='audio/mp3')
418
+
419
+ # Download button for audio
420
+ st.download_button(
421
+ "πŸ“₯ Download Audio",
422
+ data=audio_response.content,
423
+ file_name="background_music.mp3",
424
+ mime="audio/mp3"
425
+ )
426
+ else:
427
+ st.error("Failed to load audio preview")
428
+ except Exception as e:
429
+ st.error(f"Error playing audio: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
431
  with tab3:
432
  display_debug_logs()