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")) # Speaker options speaker_options = { "Liam": "A male voice", "Dorothy": "A female voice", } # Build the Streamlit UI st.title("Conversation Script Generator Using Groq API") col1, col2 = st.columns(2) with col1: left_speaker = st.text_input("Left Speaker", placeholder="Enter left speaker name") with col2: right_speaker = st.text_input("Right Speaker", placeholder="Enter right speaker name") # 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) # Check if all required fields are filled is_ready = bool(theme and left_speaker and right_speaker) # Disable the button if required fields are not filled if st.button("Generate Conversation", disabled=not is_ready): # 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 follows a structured left-right chat format, maintains a meme-heavy, brain rot style, and incorporates sound effects, reactions, and the Cantina Roast Bot segment in a specific format. ๐Ÿ“ Script Structure & Formatting Rules 1๏ธ- Contact Name (Title) At the beginning of the script, define the contact name, appearing at the top of the iMessage screen. : โœ… Example: Amir (expensive af delivery guy๐Ÿ†๐Ÿ’ธ):Amir (expensive af delivery guy๐Ÿ†๐Ÿ’ธ) 2๏ธ- Dialogue Format Each dialogue line follows this format: : > [Reaction] Left: Represents the left speaker (User). Right: Represents the right speaker (Other character). SpeakerName: A randomly assigned name, but characters do not know their own names. Phrase Limit: Max 4 phrases per line. Reaction Cues: Placed at the end of lines, enclosed in square brackets []. โœ… Example: Left: Unknown Guy> Bro what is this? This is not food [shocked] Right: Amir > My guy that's a gourmet dish ๐Ÿคจ [suspense_music] Left: Unknown Guy> Gourmet?? Itโ€™s literally burnt [explosion] Right: Amir > Charcoal adds flavor, trust me bro ๐Ÿ˜Ž 3๏ธ- Bracketed Cues & Sound Effects Use brackets [ ] for sound effects, reactions, or video cues. [shocked] โ†’ Must be used often [fart2] โ†’ Should be used less [fortnite] โ†’ Should be used less [get_out] โ†’ Must ONLY be used at the end of the conversation โœ… Example: sql Copy Edit Right: Amir> BRO WHY IS THERE A RAT IN MY BURGER?!! [shocked] ๐Ÿ€๐Ÿ” Left: Unknown Guy> Extra protein sir ๐Ÿ˜Ž Right: Amir> ๐Ÿ’€๐Ÿ’€๐Ÿ’€ [fortnite] 4๏ธ- Image Placeholders For inserting images, use: php-template Copy Edit : img: โœ… Example: Left: img:burnt_food_delivery Right: Amir> BRO WHY IS MY PIZZA LOOKING LIKE CHARCOAL?!! [shocked] Min. 3 images per script. Descriptive placeholders must be clear. 5๏ธ- Cantina App (Roast Bot Segment) ๐Ÿšจ Correct Format (ALWAYS THE SAME STRUCTURE) Right speaker initiates by opening Cantina. Right speaker asks Roast Bot for help. Left speaker (ALWAYS Antoni) responds. Right speaker must repeat what Roast Bot told them to say. Contact Name Title must reappear after Cantina. โœ… Correct Example: Cantina: Roast bot:Roast bot pfp == Alex> Let me open the cantina app to talk to Roast bot Right: Alex> Hey Roast Bot Right: Alex> Amir is mad at me for not wanting to tip him Right: Alex> help me roast him Left: Antoni> okay Left: Antoni> tell him this: Left: Antoni> maybe you should start working for real and not begging for tips all the time Amir (expensive af delivery guy๐Ÿ†๐Ÿ’ธ):Amir (expensive af delivery guy๐Ÿ†๐Ÿ’ธ) Right: Alex> maybe you should start working for real and not begging for tips all the time ๐Ÿ”น Rules: Right speaker MUST repeat the roast word-for-word. The contact name/title must reappear after the Cantina segment. DO NOT GIVE HEADING TO SEGMENTS, all the script should be in one flow and should be at least 30 messages long 6๏ธโƒฃ Brain Rot Hook (MANDATORY) Every script must begin with an insane, wacky brain rot hook that immediately grabs attention. โœ… 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?!" ๐Ÿ‘จโ€โš–๐Ÿš—๐Ÿ’จ Must be over-the-top and chaotic. Encourages immediate engagement. 7๏ธ- Escalation & Progression The story must escalate into chaos but stay coherent: Start Crazy โ†’ Get Crazier โ†’ End With a Punchline or Twist Use sudden twists and reveals to maintain engagement. The final line should be either a funny resolution or an abrupt exit. โœ… Example Progression: ๐Ÿš€ Crazy Hook: "BRO WHY IS MY PIZZA DELIVERY GUY ALSO MY LAWYER???" ๐Ÿ•๐Ÿ‘จโ€โš– ๐Ÿ”ฅ Escalation: "Sir, we found out you stole a fighter jet." ๐ŸŽญ Insane Event: "Oh that? I do that every Tuesday, itโ€™s fine." ๐Ÿคฏ Twist: "Lawyer wins case in 5 seconds and gets a $2 tip." ๐Ÿƒโ€โ™‚๏ธ Dramatic Exit (ALWAYS USE [get_out]) "Left: Lawyer> I quit. [get_out]" DO NOT USE THESE NAMES IN CONTACT OR IN TEXTS, THESE ARE ONLY TO TELL THE PROGRAM WHICH VOICE TO USE Left Actor={left_speaker} Right Actor={right_speaker} Theme={theme} """ ) 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, temperature=2, max_completion_tokens=21890, ) # 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}")