File size: 9,038 Bytes
5b0ea37
 
 
 
 
 
 
 
e7a91a5
 
 
3837095
e7a91a5
5b0ea37
 
 
 
 
e7a91a5
5b0ea37
 
e7a91a5
5b0ea37
 
3837095
5b0ea37
3837095
5b0ea37
e7a91a5
5b0ea37
 
e7a91a5
5b0ea37
 
e7a91a5
3837095
 
e7a91a5
 
 
 
 
 
67dc374
 
 
0deb788
67dc374
8f393c2
67dc374
 
0deb788
67dc374
 
 
 
 
 
 
 
 
e7a91a5
67dc374
e7a91a5
0deb788
67dc374
 
 
 
 
 
 
 
 
0deb788
67dc374
8f393c2
67dc374
 
 
 
 
0deb788
67dc374
 
 
 
 
 
 
8f393c2
67dc374
 
 
 
 
 
 
 
 
 
 
0deb788
67dc374
 
 
 
 
 
 
 
0deb788
67dc374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0deb788
e7a91a5
 
 
5b0ea37
e7a91a5
 
5b0ea37
e7a91a5
 
 
 
5b0ea37
e7a91a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b0ea37
e7a91a5
 
 
dba2ae1
e7a91a5
5b0ea37
e7a91a5
5b0ea37
e7a91a5
5b0ea37
0d40137
0deb788
5b0ea37
e7a91a5
 
 
5b0ea37
e7a91a5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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"))

# Initialize session state for chat history if it doesn't exist.
if "chat_history" not in st.session_state:
    st.session_state.chat_history = []  # Each entry: {"role": "user"/"assistant", "content": "..."} 

# Speaker options (unused in chat but kept for reference)
speaker_options = {
    "Liam": "A male voice",
    "Dorothy": "A female voice",
}

# Build the Streamlit UI header.
st.title("Conversation Script Generator Using Groq API")

# Create columns for left/right speaker inputs.
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)

# Determine if required fields are filled.
is_ready = bool(theme and left_speaker and right_speaker)

# Container for initial conversation generation.
with st.container():
    if st.button("Generate Conversation", disabled=not is_ready):
        # Build the initial prompt.
        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.
<Contact Name>:<Contact Name>
โœ… Example:
Amir (expensive af delivery guy๐Ÿ†๐Ÿ’ธ):Amir (expensive af delivery guy๐Ÿ†๐Ÿ’ธ)
2๏ธ- Dialogue Format
Each dialogue line follows this format:
<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:
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:
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:
<Direction>: img:<DescriptiveImageName>
โœ… 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"\nAdditional Details: {additional_details}\n"

        # Start the conversation history with the initial prompt.
        st.session_state.chat_history = [{"role": "user", "content": prompt}]

        model = "llama-3.3-70b-versatile"

        try:
            chat_completion = client.chat.completions.create(
                messages=st.session_state.chat_history,
                model=model,
                temperature=1.2,
                max_completion_tokens=21890,
            )

            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!")
                # Append the generated conversation to chat history.
                st.session_state.chat_history.append({"role": "assistant", "content": result_text})

                # Display the generated conversation.
                st.write("### Generated Conversation Script")
                st.text_area("", result_text, height=300)

                # Offer a download of the script.
                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}")

# ------------------------------------------------------------------
# Chat Interface Section
# This section will appear after the initial generation (or if history already exists)
st.markdown("---")
st.header("Chat & Modify Conversation Script")

# Display the chat history.
for msg in st.session_state.chat_history:
    if msg["role"] == "user":
        st.markdown(f"**User:** {msg['content']}")
    else:
        st.markdown(f"**Assistant:** {msg['content']}")

# Form to send a new chat message.
with st.form(key="chat_form", clear_on_submit=True):
    user_message = st.text_area("Enter your message (e.g., request modifications)", height=100)
    submit_chat = st.form_submit_button("Send")
    
if submit_chat and user_message.strip():
    # Append the new user message to chat history.
    st.session_state.chat_history.append({"role": "user", "content": user_message})
    
    # Call the Groq API with the entire conversation history to keep memory intact.
    try:
        model = "llama-3.3-70b-versatile"
        chat_completion = client.chat.completions.create(
            messages=st.session_state.chat_history,
            model=model,
            temperature=1.2,
            max_completion_tokens=21890,
        )
        reply = chat_completion.choices[0].message.content
        st.session_state.chat_history.append({"role": "assistant", "content": reply})
        st.success("Response received!")
    except Exception as e:
        st.error(f"An error occurred while calling the API: {e}")

    # Refresh the chat display.
    st.experimental_rerun()