import os import io import streamlit as st from groq import Groq # Set up Groq client using the environment variable for API key. client = Groq(api_key=os.environ.get("GROQ_API_KEY")) # Define the speaker options and their descriptions. speaker_options = { "Liam": "A male voice", "Dorothy": "A female voice", "Josh": "A male voice", "Arnold": "A male voice", "Matilda": "A female voice", "Brian": "A narration voice", "Alice": "A news voice", "Bill": "A narration voice", "Callum": "A character voice", "Charlie": "A conversational voice", "Charlotte": "A character voice", "Chris": "A conversational voice", "Daniel": "A news voice", "Eric": "A voice", "George": "A narration voice", "Jessica": "A voice", "Laura": "A voice", "Lily": "A narration voice", "Sarah": "A news voice", "Will": "A voice" } # Build the Streamlit UI. st.title("Conversation Script Generator Using Groq API") # Layout two columns for speaker selection. col1, col2 = st.columns(2) with col1: left_speaker = st.selectbox( "Left Speaker", options=list(speaker_options.keys()), format_func=lambda x: f"{x}: {speaker_options[x]}" ) with col2: right_speaker = st.selectbox( "Right Speaker", options=list(speaker_options.keys()), format_func=lambda x: f"{x}: {speaker_options[x]}" ) # Text area for overall conversation theme. theme = st.text_area("Overall Theme of the Conversation", height=100) # Optional additional details. additional_details = st.text_area("Additional Conversation Details (Optional)", height=100) # When the user clicks the button, build the prompt and make the API call. if st.button("Generate Conversation"): # Build the prompt message for Groq API. prompt = ( f""" Objective: Generate a highly engaging and comedic iMessage chat script formatted for video generation. The script should use distinct left and right voices, follow a structured format, and maintain a brain rot hook to keep the audience engaged. The story should be wacky, over-the-top, and meme-inspired while staying coherent. 1. FORMAT STRUCTURE (Regex-like Guide) 1.1 Contact Name (Title) At the beginning of the script, define the contact name (the name that appears at the top of the iMessage screen). php-template Copy Edit : Example: ruby Copy Edit Amir Uber Eats๐Ÿ”๐Ÿšš๐Ÿ—ฟ:Amir Uber Eats๐Ÿ”๐Ÿšš๐Ÿ—ฟ 1.2 Dialogue Format Every dialogue line should follow this structure: php-template Copy Edit : > [] โ†’ Either Left: or Right: Left: represents the left speaker (User). Right: represents the right speaker (Other character). โ†’ The voice actor name (which should remain consistent for left and right). > โ†’ A separator between the speaker name and their dialogue. โ†’ The actual speech text, containing humor, slang, or randomness. [] (Optional) โ†’ Emotional or sound-based cues (e.g., [shocked], [fart2], [get_out]). Example: vbnet Copy Edit Left: Chinmay> Sir this is your Uber Eats order [shocked] Right: Alex> BRO WHY IS THERE A RAT IN MY BURGER?!! [shocked] ๐Ÿ€๐Ÿ” Left: Chinmay> Extra protein sir ๐Ÿ˜Ž 1.3 Bracketed Cues & Sound Effects Use brackets [] to include sound effects, reactions, or video cues. DO NOT USE REACTIONS TOO OFTEN -- ONLY WHEN NECESSARY FOR DRAMATIC EFFECT Common Examples: [shocked] โ†’ Indicates the character is shocked. [get_out] โ†’ Indicates the end of the conversation or dramatic exit. [fart2] โ†’ Represents a comedic fart sound. [suspense_music] โ†’ A cue for background music. [explosion] โ†’ A big moment or reveal. [slow_zoom] โ†’ A slow zoom-in effect for emphasis. Example: css Copy Edit Right: Alex> WHY DID MY HOUSE JUST EXPLODE?!!! [explosion] ๐Ÿ’€๐Ÿ’€๐Ÿ’€ 1.4 Image Placeholders Images should be inserted where necessary using: php-template Copy Edit : img: โ†’ Describe the image clearly for easy attachment later. Example: vbnet Copy Edit Left: img:burnt_food_delivery Right: Alex> BRO WHY IS MY PIZZA LOOKING LIKE CHARCOAL?!! [shocked] 1.5 Special Sections (Cantina App / Roast Bot) Incorporate Roast Bot mechanics where the character opens an app mid-conversation to ask for a roast. Format: vbnet Copy Edit Cantina: Roast bot:Roast bot pfp == Let me open the cantina app to talk to Roast bot Then, the roast bot provides a response. Example: vbnet Copy Edit Cantina: Roast bot:Roast bot pfp == Alex> Let me open the cantina app to talk to Roast bot Right: Alex> This guy just delivered my food and scammed me ๐Ÿ˜ก Left: Antoni> Tell him this: "Sir, you pay less than a dollar tip and expect a five-star service?" Right: Alex> YOU DID ME DIRTY BRO ๐Ÿ˜ญ๐Ÿ˜ญ 2. STORY GENERATION GUIDELINES 2.1 Catchy โ€œBrain Rotโ€ Hook The first few lines must be highly engaging, over-the-top, and create curiosity. Examples: "BRO I JUST ORDERED UBER EATS AND THIS GUY SHOWED UP IN A SPACESHIP???" ๐Ÿš€๐Ÿ‘€ "WHY DID MY DAD JUST SAY HE WANTS TO PLAY GTA WITH ME???" ๐ŸŽฎ๐Ÿ’€ "SIR WHY IS MY LAWYER ALSO MY UBER DRIVER?!" ๐Ÿ‘จโ€โš–๏ธ๐Ÿš—๐Ÿ’จ This hook should create an instant โ€œWTF?!โ€ reaction and force the reader to keep watching. 2.2 Story Progression (Random but Coherent) The storyline must escalate in craziness but still have a logical flow. Use sudden twists and reveals to keep the audience engaged. End with a memorable punchline, twist, or dramatic exit. Example Storyline Flow: Crazy Hook: โ€œBRO WHY IS MY PIZZA DELIVERY GUY ALSO MY LAWYER???โ€ ๐Ÿ•๐Ÿ‘จโ€โš–๏ธ Escalation: The lawyer admits he took the case without reading it. Insane Event: The customer confesses to stealing a fighter jet. Twist: Lawyer says, โ€œOh I do that every day, sir.โ€ ๐Ÿ˜Ž Final Joke/Twist: The lawyer wins the case in 5 seconds and gets a $2 tip. 2.3 Humor & Slang Use casual meme-inspired language (brain rot humor). Include exaggerated reactions (e.g., "BROOO ๐Ÿ’€๐Ÿ’€๐Ÿ’€", "NO WAY", "HELP ME"). Use text formatting like uppercase for dramatic lines. Example: vbnet Copy Edit Right: Alex> BRO WTF IS THIS BURGER?! [shocked] Left: Chinmay> Sir, it's called a **mystery meat special** ๐Ÿ˜Ž Right: Alex> MYSTERY??? FROM WHAT ANIMAL?!?! Left: Chinmay> ๐Ÿ˜ถ 3. PARAMETERS & CUSTOMIZATION OPTIONS When prompting the AI, specify the following: Left and Right Voice Actors โ†’ Who will play each side (e.g., AI voice "John" for left, "Jake" for right). Story Theme โ†’ Choose a base premise (e.g., "Uber Eats Disaster", "Courtroom Chaos", "Dad Discovers GTA"). Left Actor={left_speaker} Right Actor={right_speaker} Theme={theme} Here is a sample script DO your best to match the length of this script and also the frequency of images, reactions and dramatic effects while keeping the story follow the theme FLAT CHEST๐Ÿซถ๐Ÿป๐Ÿฅถ๐Ÿ’:FLAT CHEST๐Ÿซถ๐Ÿป๐Ÿฅถ๐Ÿ’ Right: img:image1 [0.5] Right: Alex> Babe I survived!!! Right: Alex> I am the only one who made it out! Right: Alex> Looks like My Fortnite skills came in handy! [shocked] Left: Natasha> Fortnite skills? Right: Alex> I was cracking 90's [shocked] Left: Natasha> well we had a funeral party Right: Alex> funeral party? Right: Alex> sounds fun Right: Alex> Why wasn't I invited? Left: Natasha> Well you're not gonna like this! Left: img:image2 Left: Natasha> Meet "Mr Upgrade" == Meet Mr Upgrade [shocked] Right: Alex> Gone for a week, and you're with this dude already? Left: Natasha> Life moves fast Jason. Unlike your plane!!! [shocked] Cantina: Roast bot:Roast bot pfp == Alex> Let me open the cantina app to talk to Roast bot to ask him for a roast Right: Alex> hey roastbot Right: img:image4 Right: SHE CHEATED ON ME!!! Right: Alex> how can I roast her Left: Antoni> No problem bro Left: Antoni> just say this: you know what moves faster than life? Left: Antoni> your legs when you're running away from your husband with his best friend's credit card, sl{u}t FLAT CHEST๐Ÿซถ๐Ÿป๐Ÿฅถ๐Ÿ’:FLAT CHEST๐Ÿซถ๐Ÿป๐Ÿฅถ๐Ÿ’ Right: Alex> you know what moves faster than life? Right: Alex> your legs when you're running away from your husband with his best friend's credit card, sl{u}t [shocked] Left: Natasha> Yeah and your d{ic}k is a ghost, nobody feels it [shocked] Right: Alex> Alright, I'm coming over Right: Alex> Time to meet "Mr Upgrade" in person == Time to meet Mr Upgrade in person Left: Natasha> Uhhh maybe don't? Left: Natasha> You need rest Left: Natasha> You know post-crash trauma!!! Right: Alex> Trauma? Right: Alex> Babe are you hiding something? Left: Natasha> Hiding? Left: Natasha> Me? Left: Natasha> Never! Right: Alex> Too late Right: Alex> I'm here Left: Natasha> Ogh Fine! Left: Natasha> We're married now Left: Natasha> Okay? Right: Alex> Married?! Right: Alex> I crashed for a week and you're already hitched? [shocked] FLAT CHEST๐Ÿซถ๐Ÿป๐Ÿฅถ๐Ÿ’:FLAT CHEST๐Ÿซถ๐Ÿป๐Ÿฅถ๐Ÿ’ Left: Natasha> Hey Left: Natasha> I am single again๐Ÿ˜‚ Left: Natasha> Miss me? Right: Alex> Who's this? Left: Natasha> Your EX Left: Natasha> "Upgrade" didn't work out! == Upgrade didn't work out! Left: Natasha> I've got a kid now Left: Natasha> Wannna be his daddy? Right: Alex> Funny you asked Right: Alex> I got married Left: Natasha> Wait... Married? Left: Natasha> with whom? Left: Natasha> Jelissa? Right: Alex> Let's just say... Right: Alex> I got an upgrade๐Ÿซฆ๐Ÿ˜ Right: img:image3 Right: Alex> Stole your man bi{tch} [get_out] """ ) if additional_details.strip(): prompt += f"Additional Details: {additional_details}\n" # Prepare the message payload for the Groq API call. messages = [ { "role": "user", "content": prompt, } ] # Model selection: adjust as needed. model = "llama-3.3-70b-versatile" try: # Make the chat completion call using Groq. chat_completion = client.chat.completions.create( messages=messages, model=model, ) # Extract the generated conversation from the API response. result_text = chat_completion.choices[0].message.content if not result_text: st.error("The API call did not return any content.") else: st.success("Conversation generated successfully!") # Display the result inside a text area. st.write("### Generated Conversation Script") st.text_area("", result_text, height=300) # Create a downloadable TXT file. txt_bytes = result_text.encode("utf-8") txt_io = io.BytesIO(txt_bytes) st.download_button( label="Download Script as TXT", data=txt_io, file_name="conversation_script.txt", mime="text/plain" ) except Exception as e: st.error(f"An error occurred while calling the API: {e}")