Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,15 @@ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
|
8 |
|
9 |
# Initialize session state for chat history if it doesn't exist.
|
10 |
if "chat_history" not in st.session_state:
|
11 |
-
st.session_state.chat_history = [] #
|
12 |
|
13 |
-
def
|
14 |
-
"""Render the
|
15 |
chat_container = st.container()
|
16 |
chat_md = ""
|
17 |
for msg in st.session_state.chat_history:
|
18 |
-
if msg["role"] == "
|
19 |
-
chat_md += f"**
|
20 |
-
else:
|
21 |
-
chat_md += f"**Assistant:** {msg['content']}\n\n"
|
22 |
chat_container.markdown(chat_md)
|
23 |
|
24 |
st.title("Conversation Script Generator Using Groq API")
|
@@ -41,21 +39,17 @@ additional_details = st.text_area("Additional Conversation Details (Optional)",
|
|
41 |
is_ready = bool(theme and left_speaker and right_speaker and contact_name)
|
42 |
|
43 |
if st.button("Generate Conversation", disabled=not is_ready):
|
44 |
-
# Build the initial prompt.
|
45 |
prompt = f"""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
1️ Contact Name (Title)
|
50 |
At the beginning of the script, define the contact name, appearing at the top of the iMessage screen.
|
51 |
-
|
52 |
<Contact Name>:<Contact Name>
|
53 |
✅ Example:
|
54 |
-
|
55 |
Liam (Black Market Electronics Dealer 📱💸):Liam (Black Market Electronics Dealer 📱💸)
|
56 |
2️ Dialogue Format
|
57 |
Each dialogue line follows this format:
|
58 |
-
|
59 |
<Direction>: <SpeakerName> > <Phrase 1> <Phrase 2> <Phrase 3> <Phrase 4> [Reaction]
|
60 |
Left: Represents the left speaker (User).
|
61 |
Right: Represents the right speaker (Other character).
|
@@ -63,45 +57,37 @@ SpeakerName: A randomly assigned alias (characters do not know their own names).
|
|
63 |
Phrase Limit: Max 4 phrases per line.
|
64 |
Reaction Cues: Placed at the end of lines, enclosed in square brackets [].
|
65 |
✅ Example:
|
66 |
-
|
67 |
Left: MysteryGuy> BRO WHY IS MY COMPUTER SPEAKING LATIN??? [shocked]
|
68 |
Right: Liam> Uh… you *might* have summoned something 💀 [suspense_music]
|
69 |
Left: MysteryGuy> SUMMONED WHAT???
|
70 |
Right: Liam> 😶
|
71 |
3️ Bracketed Cues & Sound Effects
|
72 |
Use brackets [ ] for sound effects, reactions, or video cues.
|
73 |
-
|
74 |
[shocked] → Must be used often
|
75 |
[fart2] → Should be used less
|
76 |
[fortnite] → Should be used less
|
77 |
[get_out] → Must ONLY be used at the end of the conversation
|
78 |
✅ Example:
|
79 |
-
|
80 |
-
|
81 |
Right: Max> BRO WHY IS THERE A ROBOT FOLLOWING ME?!! [shocked] 🤖
|
82 |
Left: UnknownDude> Congrats, you just activated *follow mode* 😎
|
83 |
Right: Max> FOLLOW MODE??? TURN IT OFF
|
84 |
Left: UnknownDude> nahhh that's a premium feature 🤣💀 [fortnite]
|
85 |
4️ Image Placeholders
|
86 |
For inserting images, use:
|
87 |
-
|
88 |
<Direction>: img:<DescriptiveImageName>
|
89 |
✅ Example:
|
90 |
-
|
91 |
Left: img:ancient_phone_booting_up
|
92 |
Right: Liam> WHY DID MY OLD NOKIA JUST START SCREAMING??? [shocked]
|
93 |
Min. 3 images per script.
|
94 |
Descriptive placeholders must be varied and clear.
|
95 |
5️⃣ Cantina App (Roast Bot Segment)
|
96 |
🚨 Correct Format (ALWAYS THE SAME STRUCTURE)
|
97 |
-
|
98 |
Right speaker initiates by opening Cantina.
|
99 |
Right speaker asks Roast Bot for help.
|
100 |
Left speaker (ALWAYS Antoni) responds.
|
101 |
Right speaker must repeat what Roast Bot told them to say.
|
102 |
Contact Name Title must reappear after Cantina.
|
103 |
✅ Correct Example:
|
104 |
-
|
105 |
Cantina: Roast bot:Roast bot pfp == Alex> Let me open the cantina app to talk to Roast bot
|
106 |
Right: Alex> Hey Roast Bot
|
107 |
Right: Alex> Liam is mad at me for borrowing his Tesla without permission
|
@@ -114,15 +100,12 @@ Right: Alex> maybe if you had better security, you wouldn’t have to track your
|
|
114 |
🚫 Incorrect Example (DO NOT DO THIS):
|
115 |
Cantina: Roast bot:Roast bot pfp == Liam> Hey Roast Bot, we need your help! My AI fridge is trying to blackmail me! ❌
|
116 |
🔹 Rules:
|
117 |
-
|
118 |
Left Speaker in Cantina is ALWAYS "Antoni."
|
119 |
Right speaker MUST repeat the roast word-for-word.
|
120 |
The contact name/title must reappear after the Cantina segment.
|
121 |
6️ Brain Rot Hook (MANDATORY)
|
122 |
Every script must begin with an insane, wacky brain rot hook that immediately grabs attention.
|
123 |
-
|
124 |
✅ Examples:
|
125 |
-
|
126 |
"WHY DID MY TV JUST ASK ME FOR A PASSWORD???" 📺🔑
|
127 |
"BRO MY DOG JUST SENT ME A TEXT MESSAGE???" 🐶📲
|
128 |
"WHY IS MY LANDLORD SELLING MY HOUSE ON FACEBOOK MARKETPLACE???" 🏠💀
|
@@ -130,12 +113,10 @@ Must be over-the-top and chaotic.
|
|
130 |
Encourages immediate engagement.
|
131 |
7️ Escalation & Progression
|
132 |
The story must escalate into chaos but stay coherent:
|
133 |
-
|
134 |
Start Crazy → Get Crazier → End With a Punchline or Twist
|
135 |
Use sudden twists and reveals to maintain engagement.
|
136 |
The final line should be either a funny resolution or an abrupt exit.
|
137 |
✅ Example Progression:
|
138 |
-
|
139 |
🚀 Crazy Hook:
|
140 |
"BRO WHY DID MY PHONE JUST ORDER A UBER ON ITS OWN???" 🚗💨
|
141 |
🔥 Escalation:
|
@@ -148,12 +129,10 @@ The final line should be either a funny resolution or an abrupt exit.
|
|
148 |
"Left: UnknownDude> Enjoy the ride 😎 [get_out]"
|
149 |
8️⃣ Speaker Name Randomization
|
150 |
🚨 Speakers should NOT know their own names.
|
151 |
-
|
152 |
Left speaker’s name should always appear as "Unknown Guy" or a random alias.
|
153 |
Right speaker’s name should also be replaced with something generic unless necessary.
|
154 |
The system should NOT recognize them.
|
155 |
✅ Example:
|
156 |
-
|
157 |
Left: MysteriousCaller> BRO WHO JUST HACKED MY PHONE??? [shocked]
|
158 |
Right: HackerDude> Oh, don’t worry, it's just an update 😎
|
159 |
Left: MysteriousCaller> UPDATE??? BRO WHAT DO YOU MEAN
|
@@ -164,7 +143,6 @@ Emoji Button → Clicking adds 5 random emojis to any phrase.
|
|
164 |
Max 9 sound effect commands, with [shocked] used most.
|
165 |
Final Parameters & Instructions
|
166 |
When prompting the AI, specify:
|
167 |
-
|
168 |
Left Actor = {left_speaker}
|
169 |
Right Actor = {right_speaker}
|
170 |
Theme = {theme} (e.g., “AI Gone Wrong”, “Haunted Electronics”, “Unexpected Legal Trouble”)
|
@@ -178,7 +156,6 @@ Speaker names are randomized and unknown to them.
|
|
178 |
🔹 Cantina Roast Bot always follows the same structure.
|
179 |
🔹 Brain rot hook is mandatory.
|
180 |
🔹 Escalates into chaos but remains coherent.
|
181 |
-
|
182 |
Contact Name: {contact_name}
|
183 |
{contact_name} : {contact_name} in the start
|
184 |
Left Speaker: {left_speaker}
|
@@ -204,7 +181,6 @@ for right ones
|
|
204 |
max_completion_tokens=21890,
|
205 |
)
|
206 |
result_text = chat_completion.choices[0].message.content
|
207 |
-
|
208 |
if not result_text:
|
209 |
st.error("The API call did not return any content.")
|
210 |
else:
|
@@ -214,7 +190,7 @@ for right ones
|
|
214 |
st.error(f"An error occurred while calling the API: {e}")
|
215 |
|
216 |
st.markdown("### Generated Conversation Script")
|
217 |
-
|
218 |
|
219 |
# ---------------------------
|
220 |
# Chat Interface for Revisions
|
@@ -233,14 +209,14 @@ if submit_chat and user_message.strip():
|
|
233 |
if msg["role"] == "assistant":
|
234 |
last_script = msg["content"]
|
235 |
break
|
236 |
-
# Build a
|
237 |
revision_prompt = f"""Revision Request: {user_message}
|
238 |
|
239 |
Context: The current conversation script is as follows:
|
240 |
|
241 |
{last_script}
|
242 |
|
243 |
-
Please revise the script to incorporate the
|
244 |
"""
|
245 |
st.session_state.chat_history.append({"role": "user", "content": revision_prompt})
|
246 |
|
@@ -259,7 +235,7 @@ Please revise the script to incorporate the above requested changes. Do not simp
|
|
259 |
st.error(f"An error occurred while calling the API: {e}")
|
260 |
|
261 |
st.markdown("### Updated Conversation Script")
|
262 |
-
|
263 |
|
264 |
# ---------------------------
|
265 |
# Download Option for the Latest Assistant Script
|
|
|
8 |
|
9 |
# Initialize session state for chat history if it doesn't exist.
|
10 |
if "chat_history" not in st.session_state:
|
11 |
+
st.session_state.chat_history = [] # Each item is a dict: {"role": "user"/"assistant", "content": "..."}
|
12 |
|
13 |
+
def render_assistant_history():
|
14 |
+
"""Render only the assistant responses from the conversation history."""
|
15 |
chat_container = st.container()
|
16 |
chat_md = ""
|
17 |
for msg in st.session_state.chat_history:
|
18 |
+
if msg["role"] == "assistant":
|
19 |
+
chat_md += f"**Assistant:**\n{msg['content']}\n\n"
|
|
|
|
|
20 |
chat_container.markdown(chat_md)
|
21 |
|
22 |
st.title("Conversation Script Generator Using Groq API")
|
|
|
39 |
is_ready = bool(theme and left_speaker and right_speaker and contact_name)
|
40 |
|
41 |
if st.button("Generate Conversation", disabled=not is_ready):
|
|
|
42 |
prompt = f"""
|
43 |
+
Youe Task is to generate an engaging script which is a conversation between two people on iMessage for meme purposes.. It should strictly follow a given
|
44 |
+
syntax and should be diverse and creative
|
45 |
+
Script Structure & Formatting Rules
|
46 |
1️ Contact Name (Title)
|
47 |
At the beginning of the script, define the contact name, appearing at the top of the iMessage screen.
|
|
|
48 |
<Contact Name>:<Contact Name>
|
49 |
✅ Example:
|
|
|
50 |
Liam (Black Market Electronics Dealer 📱💸):Liam (Black Market Electronics Dealer 📱💸)
|
51 |
2️ Dialogue Format
|
52 |
Each dialogue line follows this format:
|
|
|
53 |
<Direction>: <SpeakerName> > <Phrase 1> <Phrase 2> <Phrase 3> <Phrase 4> [Reaction]
|
54 |
Left: Represents the left speaker (User).
|
55 |
Right: Represents the right speaker (Other character).
|
|
|
57 |
Phrase Limit: Max 4 phrases per line.
|
58 |
Reaction Cues: Placed at the end of lines, enclosed in square brackets [].
|
59 |
✅ Example:
|
|
|
60 |
Left: MysteryGuy> BRO WHY IS MY COMPUTER SPEAKING LATIN??? [shocked]
|
61 |
Right: Liam> Uh… you *might* have summoned something 💀 [suspense_music]
|
62 |
Left: MysteryGuy> SUMMONED WHAT???
|
63 |
Right: Liam> 😶
|
64 |
3️ Bracketed Cues & Sound Effects
|
65 |
Use brackets [ ] for sound effects, reactions, or video cues.
|
|
|
66 |
[shocked] → Must be used often
|
67 |
[fart2] → Should be used less
|
68 |
[fortnite] → Should be used less
|
69 |
[get_out] → Must ONLY be used at the end of the conversation
|
70 |
✅ Example:
|
|
|
|
|
71 |
Right: Max> BRO WHY IS THERE A ROBOT FOLLOWING ME?!! [shocked] 🤖
|
72 |
Left: UnknownDude> Congrats, you just activated *follow mode* 😎
|
73 |
Right: Max> FOLLOW MODE??? TURN IT OFF
|
74 |
Left: UnknownDude> nahhh that's a premium feature 🤣💀 [fortnite]
|
75 |
4️ Image Placeholders
|
76 |
For inserting images, use:
|
|
|
77 |
<Direction>: img:<DescriptiveImageName>
|
78 |
✅ Example:
|
|
|
79 |
Left: img:ancient_phone_booting_up
|
80 |
Right: Liam> WHY DID MY OLD NOKIA JUST START SCREAMING??? [shocked]
|
81 |
Min. 3 images per script.
|
82 |
Descriptive placeholders must be varied and clear.
|
83 |
5️⃣ Cantina App (Roast Bot Segment)
|
84 |
🚨 Correct Format (ALWAYS THE SAME STRUCTURE)
|
|
|
85 |
Right speaker initiates by opening Cantina.
|
86 |
Right speaker asks Roast Bot for help.
|
87 |
Left speaker (ALWAYS Antoni) responds.
|
88 |
Right speaker must repeat what Roast Bot told them to say.
|
89 |
Contact Name Title must reappear after Cantina.
|
90 |
✅ Correct Example:
|
|
|
91 |
Cantina: Roast bot:Roast bot pfp == Alex> Let me open the cantina app to talk to Roast bot
|
92 |
Right: Alex> Hey Roast Bot
|
93 |
Right: Alex> Liam is mad at me for borrowing his Tesla without permission
|
|
|
100 |
🚫 Incorrect Example (DO NOT DO THIS):
|
101 |
Cantina: Roast bot:Roast bot pfp == Liam> Hey Roast Bot, we need your help! My AI fridge is trying to blackmail me! ❌
|
102 |
🔹 Rules:
|
|
|
103 |
Left Speaker in Cantina is ALWAYS "Antoni."
|
104 |
Right speaker MUST repeat the roast word-for-word.
|
105 |
The contact name/title must reappear after the Cantina segment.
|
106 |
6️ Brain Rot Hook (MANDATORY)
|
107 |
Every script must begin with an insane, wacky brain rot hook that immediately grabs attention.
|
|
|
108 |
✅ Examples:
|
|
|
109 |
"WHY DID MY TV JUST ASK ME FOR A PASSWORD???" 📺🔑
|
110 |
"BRO MY DOG JUST SENT ME A TEXT MESSAGE???" 🐶📲
|
111 |
"WHY IS MY LANDLORD SELLING MY HOUSE ON FACEBOOK MARKETPLACE???" 🏠💀
|
|
|
113 |
Encourages immediate engagement.
|
114 |
7️ Escalation & Progression
|
115 |
The story must escalate into chaos but stay coherent:
|
|
|
116 |
Start Crazy → Get Crazier → End With a Punchline or Twist
|
117 |
Use sudden twists and reveals to maintain engagement.
|
118 |
The final line should be either a funny resolution or an abrupt exit.
|
119 |
✅ Example Progression:
|
|
|
120 |
🚀 Crazy Hook:
|
121 |
"BRO WHY DID MY PHONE JUST ORDER A UBER ON ITS OWN???" 🚗💨
|
122 |
🔥 Escalation:
|
|
|
129 |
"Left: UnknownDude> Enjoy the ride 😎 [get_out]"
|
130 |
8️⃣ Speaker Name Randomization
|
131 |
🚨 Speakers should NOT know their own names.
|
|
|
132 |
Left speaker’s name should always appear as "Unknown Guy" or a random alias.
|
133 |
Right speaker’s name should also be replaced with something generic unless necessary.
|
134 |
The system should NOT recognize them.
|
135 |
✅ Example:
|
|
|
136 |
Left: MysteriousCaller> BRO WHO JUST HACKED MY PHONE??? [shocked]
|
137 |
Right: HackerDude> Oh, don’t worry, it's just an update 😎
|
138 |
Left: MysteriousCaller> UPDATE??? BRO WHAT DO YOU MEAN
|
|
|
143 |
Max 9 sound effect commands, with [shocked] used most.
|
144 |
Final Parameters & Instructions
|
145 |
When prompting the AI, specify:
|
|
|
146 |
Left Actor = {left_speaker}
|
147 |
Right Actor = {right_speaker}
|
148 |
Theme = {theme} (e.g., “AI Gone Wrong”, “Haunted Electronics”, “Unexpected Legal Trouble”)
|
|
|
156 |
🔹 Cantina Roast Bot always follows the same structure.
|
157 |
🔹 Brain rot hook is mandatory.
|
158 |
🔹 Escalates into chaos but remains coherent.
|
|
|
159 |
Contact Name: {contact_name}
|
160 |
{contact_name} : {contact_name} in the start
|
161 |
Left Speaker: {left_speaker}
|
|
|
181 |
max_completion_tokens=21890,
|
182 |
)
|
183 |
result_text = chat_completion.choices[0].message.content
|
|
|
184 |
if not result_text:
|
185 |
st.error("The API call did not return any content.")
|
186 |
else:
|
|
|
190 |
st.error(f"An error occurred while calling the API: {e}")
|
191 |
|
192 |
st.markdown("### Generated Conversation Script")
|
193 |
+
render_assistant_history()
|
194 |
|
195 |
# ---------------------------
|
196 |
# Chat Interface for Revisions
|
|
|
209 |
if msg["role"] == "assistant":
|
210 |
last_script = msg["content"]
|
211 |
break
|
212 |
+
# Build a revision prompt including context and user request.
|
213 |
revision_prompt = f"""Revision Request: {user_message}
|
214 |
|
215 |
Context: The current conversation script is as follows:
|
216 |
|
217 |
{last_script}
|
218 |
|
219 |
+
Please revise the script to incorporate the requested changes. Do not simply repeat the same content—update it with new, modified details reflecting the user's instructions.
|
220 |
"""
|
221 |
st.session_state.chat_history.append({"role": "user", "content": revision_prompt})
|
222 |
|
|
|
235 |
st.error(f"An error occurred while calling the API: {e}")
|
236 |
|
237 |
st.markdown("### Updated Conversation Script")
|
238 |
+
render_assistant_history()
|
239 |
|
240 |
# ---------------------------
|
241 |
# Download Option for the Latest Assistant Script
|