Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -384,94 +384,71 @@ def main():
|
|
| 384 |
st.json(st.session_state.generated_content)
|
| 385 |
|
| 386 |
with tab2:
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
st.download_button(
|
| 409 |
-
"π₯ Download Image",
|
| 410 |
-
data=final_image,
|
| 411 |
-
file_name="spiritual_quote.jpg",
|
| 412 |
-
mime="image/jpeg"
|
| 413 |
-
)
|
| 414 |
-
|
| 415 |
-
with col2:
|
| 416 |
-
# Audio preview
|
| 417 |
-
st.subheader("π΅ Background Music")
|
| 418 |
-
if st.session_state.generated_audio:
|
| 419 |
-
try:
|
| 420 |
-
audio_response = requests.get(st.session_state.generated_audio)
|
| 421 |
-
if audio_response.status_code == 200:
|
| 422 |
-
st.audio(audio_response.content, format='audio/mp3')
|
| 423 |
-
st.download_button(
|
| 424 |
-
"π₯ Download Audio",
|
| 425 |
-
data=audio_response.content,
|
| 426 |
-
file_name="background_music.mp3",
|
| 427 |
-
mime="audio/mp3"
|
| 428 |
-
)
|
| 429 |
-
|
| 430 |
-
# Add caption and hashtags
|
| 431 |
-
st.subheader("π Caption")
|
| 432 |
-
hashtags = generate_hashtags(
|
| 433 |
-
quote_data['tradition'],
|
| 434 |
-
quote_data.get('theme', 'Wisdom')
|
| 435 |
-
)
|
| 436 |
-
caption = f"""β¨ Wisdom from {quote_data['tradition']} β¨
|
| 437 |
-
|
| 438 |
-
"{quote_data['text']}"
|
| 439 |
-
- {quote_data['author']}
|
| 440 |
-
|
| 441 |
-
{' '.join(hashtags)}"""
|
| 442 |
-
st.text_area("Instagram Caption", caption, height=200)
|
| 443 |
-
|
| 444 |
-
else:
|
| 445 |
-
st.error("Failed to load audio preview")
|
| 446 |
-
except Exception as e:
|
| 447 |
-
st.error(f"Error playing audio: {str(e)}")
|
| 448 |
-
else:
|
| 449 |
-
st.info("Generate content first to see the Instagram preview")
|
| 450 |
-
if final_image:
|
| 451 |
-
st.image(final_image)
|
| 452 |
-
|
| 453 |
-
# Audio preview
|
| 454 |
-
st.subheader("π΅ Background Music")
|
| 455 |
-
if st.session_state.generated_audio:
|
| 456 |
-
try:
|
| 457 |
-
# Get audio data from URL
|
| 458 |
-
audio_response = requests.get(st.session_state.generated_audio)
|
| 459 |
-
if audio_response.status_code == 200:
|
| 460 |
-
# Create audio player
|
| 461 |
-
st.audio(audio_response.content, format='audio/mp3')
|
| 462 |
-
|
| 463 |
-
# Download button for audio
|
| 464 |
st.download_button(
|
| 465 |
-
"π₯ Download
|
| 466 |
-
data=
|
| 467 |
-
file_name="
|
| 468 |
-
mime="
|
| 469 |
)
|
| 470 |
-
else:
|
| 471 |
-
st.error("Failed to load audio preview")
|
| 472 |
-
except Exception as e:
|
| 473 |
-
st.error(f"Error playing audio: {str(e)}")
|
| 474 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 475 |
with tab3:
|
| 476 |
display_debug_logs()
|
| 477 |
|
|
|
|
| 384 |
st.json(st.session_state.generated_content)
|
| 385 |
|
| 386 |
with tab2:
|
| 387 |
+
st.title("Instagram Preview")
|
| 388 |
+
if all([st.session_state.generated_content,
|
| 389 |
+
st.session_state.generated_image,
|
| 390 |
+
st.session_state.generated_audio]):
|
| 391 |
+
|
| 392 |
+
col1, col2 = st.columns([2, 1])
|
| 393 |
+
|
| 394 |
+
with col1:
|
| 395 |
+
# Image with quote overlay
|
| 396 |
+
quote_data = st.session_state.generated_content
|
| 397 |
+
generator = ContentGenerator(
|
| 398 |
+
st.secrets["OPENAI_API_KEY"],
|
| 399 |
+
st.secrets["REPLICATE_API_TOKEN"]
|
| 400 |
+
)
|
| 401 |
+
final_image = generator.create_image_with_quote(
|
| 402 |
+
st.session_state.generated_image,
|
| 403 |
+
quote_data['text'],
|
| 404 |
+
quote_data['author']
|
| 405 |
+
)
|
| 406 |
+
if final_image:
|
| 407 |
+
st.image(final_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
st.download_button(
|
| 409 |
+
"π₯ Download Image",
|
| 410 |
+
data=final_image,
|
| 411 |
+
file_name="spiritual_quote.jpg",
|
| 412 |
+
mime="image/jpeg"
|
| 413 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
|
| 415 |
+
with col2:
|
| 416 |
+
# Audio preview
|
| 417 |
+
st.subheader("π΅ Background Music")
|
| 418 |
+
if st.session_state.generated_audio:
|
| 419 |
+
try:
|
| 420 |
+
audio_response = requests.get(st.session_state.generated_audio)
|
| 421 |
+
if audio_response.status_code == 200:
|
| 422 |
+
st.audio(audio_response.content, format='audio/mp3')
|
| 423 |
+
st.download_button(
|
| 424 |
+
"π₯ Download Audio",
|
| 425 |
+
data=audio_response.content,
|
| 426 |
+
file_name="background_music.mp3",
|
| 427 |
+
mime="audio/mp3"
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
# Add caption and hashtags
|
| 431 |
+
st.subheader("π Caption")
|
| 432 |
+
hashtags = generate_hashtags(
|
| 433 |
+
quote_data['tradition'],
|
| 434 |
+
quote_data.get('theme', 'Wisdom')
|
| 435 |
+
)
|
| 436 |
+
caption = f"""β¨ Wisdom from {quote_data['tradition']} β¨
|
| 437 |
+
|
| 438 |
+
"{quote_data['text']}"
|
| 439 |
+
- {quote_data['author']}
|
| 440 |
+
|
| 441 |
+
{' '.join(hashtags)}"""
|
| 442 |
+
st.text_area("Instagram Caption", caption, height=200)
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
else:
|
| 446 |
+
st.error("Failed to load audio preview")
|
| 447 |
+
except Exception as e:
|
| 448 |
+
st.error(f"Error playing audio: {str(e)}")
|
| 449 |
+
else:
|
| 450 |
+
st.info("Generate content first to see the Instagram preview")
|
| 451 |
+
|
| 452 |
with tab3:
|
| 453 |
display_debug_logs()
|
| 454 |
|