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")) | |
# 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 | |
<Contact Name>:<Contact Name> | |
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 | |
<Direction>: <SpeakerName> > <Dialogue> [<Reaction>] | |
<Direction> โ Either Left: or Right: | |
Left: represents the left speaker (User). | |
Right: represents the right speaker (Other character). | |
<SpeakerName> โ The voice actor name (which should remain consistent for left and right). | |
> โ A separator between the speaker name and their dialogue. | |
<Dialogue> โ The actual speech text, containing humor, slang, or randomness. | |
[<Reaction>] (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. | |
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 | |
<Direction>: img:<DescriptiveImageName> | |
<DescriptiveImageName> โ 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 == <Speaker> 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} | |
""" | |
) | |
if additional_details.strip(): | |
prompt += f"Additional Details: {additional_details}\n" | |
# Display the generated prompt for debugging. | |
st.write("### Generated Prompt") | |
st.code(prompt) | |
# 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}") | |