|
|
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 |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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"): |
|
|
|
|
|
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()) |
|
|
|
|
|
|
|
|
st.header("π Voice Notes Holder") |
|
|
|
|
|
voice_file = st.file_uploader("Upload a voice note", type=["mp3", "wav", "m4a"]) |
|
|
if voice_file: |
|
|
|
|
|
audio_bytes = voice_file.read() |
|
|
st.audio(audio_bytes, format="audio/mp3") |
|
|
|
|
|
if st.button("Transcribe & Caption"): |
|
|
|
|
|
transcript = client.audio.transcriptions.create( |
|
|
model="whisper-1", |
|
|
file=voice_file |
|
|
) |
|
|
|
|
|
st.write("π **Transcription:**") |
|
|
st.write(transcript.text) |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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!") |
|
|
|