import streamlit as st from openai import OpenAI from PIL import Image from gtts import gTTS import os from io import BytesIO from pydub import AudioSegment # Initialize OpenAI client client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) st.set_page_config(page_title="Meme + Voice Notes App", layout="centered") st.title("🎭 Meme Generator + 🎙 Voice Notes Holder") # ========== MEME GENERATOR ========== st.header("😂 Meme Generator") uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) if uploaded_file: img = Image.open(uploaded_file) st.image(img, caption="Your Uploaded Image", use_column_width=True) if st.button("Generate Meme"): # Describe image + generate captions prompt = f"Write 3 funny, Gen Z style meme captions for a photo like this. Keep it short & witty." response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], max_tokens=100 ) captions = response.choices[0].message.content.split("\n") st.subheader("Pick Your Meme Caption") for cap in captions: if cap.strip(): st.text(cap.strip()) # ========== VOICE NOTES ========== st.header("🎙 Voice Notes Holder") voice_file = st.file_uploader("Upload a voice note", type=["mp3", "wav", "m4a"]) if voice_file: # Save uploaded voice file audio_bytes = voice_file.read() st.audio(audio_bytes, format="audio/mp3") if st.button("Transcribe & Caption"): # Transcribe audio (simplified: send raw text request) transcript = client.audio.transcriptions.create( model="whisper-1", file=voice_file ) st.write("📝 **Transcription:**") st.write(transcript.text) # Generate a funny caption for the note caption_prompt = f"Make a short funny Gen Z style caption for this voice note text: {transcript.text}" caption_response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": caption_prompt}], max_tokens=60 ) st.write("😂 **Meme Caption:**") st.write(caption_response.choices[0].message.content) # Optional: TTS the caption tts = gTTS(text=caption_response.choices[0].message.content, lang="en") tts_bytes = BytesIO() tts.save("caption.mp3") audio_file = open("caption.mp3", "rb") audio_bytes = audio_file.read() st.audio(audio_bytes, format="audio/mp3") st.markdown("---") st.info("🚀 Tip: Add a Birthday Mode with custom memes + voice surprise for your sister!")