Spaces:
Sleeping
Sleeping
| 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. | |
| php-template | |
| Copy | |
| Edit | |
| <Contact Name>:<Contact Name> | |
| โ Example: | |
| ruby | |
| Copy | |
| Edit | |
| Amir (expensive af delivery guy๐๐ธ):Amir (expensive af delivery guy๐๐ธ) | |
| 2๏ธโฃ Dialogue Format | |
| Each dialogue line follows this format: | |
| php-template | |
| Copy | |
| Edit | |
| <Direction>: <SpeakerName> > <Phrase 1> <Phrase 2> <Phrase 3> <Phrase 4> [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: | |
| vbnet | |
| Copy | |
| Edit | |
| 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 | |
| <Direction>: img:<DescriptiveImageName> | |
| โ Example: | |
| vbnet | |
| Copy | |
| Edit | |
| 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: | |
| sql | |
| Copy | |
| Edit | |
| 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 | |
| ๐ซ Incorrect Example (DO NOT DO THIS): | |
| vbnet | |
| Copy | |
| Edit | |
| Cantina: Roast bot:Roast bot pfp == Liam> Hey Roast Bot, we need your help! Amir's spaceship crashed on Mars and we need to get him back to Earth! โ | |
| ๐น Rules: | |
| Left Speaker in Cantina is ALWAYS "Antoni." | |
| Right speaker MUST repeat the roast word-for-word. | |
| The contact name/title must reappear after the Cantina segment. | |
| 6๏ธโฃ Brain Rot Hook (MANDATORY) | |
| Every script must begin with an insane, wacky brain rot hook that immediately grabs attention. | |
| โ Examples: | |
| arduino | |
| Copy | |
| Edit | |
| "๐จ 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]" | |
| 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 = "llama3-70b-8192" | |
| 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}") |