File size: 2,716 Bytes
f83acf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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!")