Spaces:
Runtime error
Runtime error
added JSON
Browse files+personality generation
app.py
CHANGED
@@ -166,8 +166,11 @@ with gr.Blocks() as demo:
|
|
166 |
sexuality = gr.Textbox(label="Sexuality", interactive=True)
|
167 |
age = gr.Slider(1, 100, label="Age", info="Choose between 1 and 100", interactive=True, step=1.0)
|
168 |
description = gr.Textbox(label="Description", interactive=True)
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
171 |
with gr.Accordion("Speaking Traits"):
|
172 |
genProfile = gr.Button("Generate Speaking Style", interactive=True)
|
173 |
with gr.Column(scale=1, min_width=600):
|
@@ -227,6 +230,7 @@ with gr.Blocks() as demo:
|
|
227 |
state = demo.state
|
228 |
state.inputs["charName"] = "New Name"
|
229 |
demo.update(state)
|
|
|
230 |
generate.click(getAndParseQuickStart, inputs=[quickStart], outputs=[
|
231 |
quickStartResult,
|
232 |
charName,
|
@@ -242,13 +246,28 @@ with gr.Blocks() as demo:
|
|
242 |
attributes
|
243 |
])
|
244 |
createJSON = gr.Button("Create JSON")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
|
|
246 |
def insertUser(text):
|
247 |
return text + "\n{{user}}"
|
248 |
def insertBot(text):
|
249 |
return text + "\n{{char}}"
|
250 |
addUser.click(insertUser, inputs=[examples], outputs=examples)
|
251 |
addBot.click(insertBot, inputs=[examples], outputs=examples)
|
|
|
252 |
genProfile.click(generateSpeakingStyle, inputs=[quickStartResult], outputs=[
|
253 |
formality,
|
254 |
pace,
|
@@ -279,6 +298,133 @@ with gr.Blocks() as demo:
|
|
279 |
cultural_references,
|
280 |
storytelling_ability
|
281 |
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
283 |
instruction_prompt = """
|
284 |
You are an AI bot that creates profiles of characters based on a simple input. You generate and give detailed characters in the following format:
|
|
|
166 |
sexuality = gr.Textbox(label="Sexuality", interactive=True)
|
167 |
age = gr.Slider(1, 100, label="Age", info="Choose between 1 and 100", interactive=True, step=1.0)
|
168 |
description = gr.Textbox(label="Description", interactive=True)
|
169 |
+
attributes = gr.Textbox(label="Attributes", interactive=True)
|
170 |
+
with gr.Row():
|
171 |
+
personalityProfile = gr.Textbox(label="Personality Profile", interactive=True)
|
172 |
+
generatePersonality = gr.Button("Analyze")
|
173 |
+
|
174 |
with gr.Accordion("Speaking Traits"):
|
175 |
genProfile = gr.Button("Generate Speaking Style", interactive=True)
|
176 |
with gr.Column(scale=1, min_width=600):
|
|
|
230 |
state = demo.state
|
231 |
state.inputs["charName"] = "New Name"
|
232 |
demo.update(state)
|
233 |
+
|
234 |
generate.click(getAndParseQuickStart, inputs=[quickStart], outputs=[
|
235 |
quickStartResult,
|
236 |
charName,
|
|
|
246 |
attributes
|
247 |
])
|
248 |
createJSON = gr.Button("Create JSON")
|
249 |
+
def makePersonality(text):
|
250 |
+
print("Asking AI for a profile")
|
251 |
+
prompt = "Here are the details for you to analyze. Remember to return in the specified format: " + text
|
252 |
+
|
253 |
+
response = openai.ChatCompletion.create(
|
254 |
+
model="gpt-4-0613",
|
255 |
+
messages=[
|
256 |
+
{"role": "system", "content": prompt_profile},
|
257 |
+
{"role": "user", "content": prompt}
|
258 |
+
])
|
259 |
+
response_content = response['choices'][0]['message']['content']
|
260 |
+
print(response_content)
|
261 |
+
return response_content
|
262 |
|
263 |
+
generatePersonality.click(makePersonality, inputs=[quickStartResult], outputs=[personalityProfile])
|
264 |
def insertUser(text):
|
265 |
return text + "\n{{user}}"
|
266 |
def insertBot(text):
|
267 |
return text + "\n{{char}}"
|
268 |
addUser.click(insertUser, inputs=[examples], outputs=examples)
|
269 |
addBot.click(insertBot, inputs=[examples], outputs=examples)
|
270 |
+
|
271 |
genProfile.click(generateSpeakingStyle, inputs=[quickStartResult], outputs=[
|
272 |
formality,
|
273 |
pace,
|
|
|
298 |
cultural_references,
|
299 |
storytelling_ability
|
300 |
])
|
301 |
+
def createJSONfile(quickStartResult,
|
302 |
+
charName,
|
303 |
+
personality,
|
304 |
+
body,
|
305 |
+
likes,
|
306 |
+
hates,
|
307 |
+
sex,
|
308 |
+
sexuality,
|
309 |
+
age,
|
310 |
+
description,
|
311 |
+
personalityProfile,
|
312 |
+
attributes,
|
313 |
+
formality,
|
314 |
+
pace,
|
315 |
+
rhythm,
|
316 |
+
volume,
|
317 |
+
emotionality,
|
318 |
+
directness,
|
319 |
+
humor,
|
320 |
+
enunciation,
|
321 |
+
expressiveness,
|
322 |
+
accent_dialect,
|
323 |
+
politeness,
|
324 |
+
vocabulary,
|
325 |
+
interruptions,
|
326 |
+
hesitations,
|
327 |
+
sentence_structure,
|
328 |
+
sarcasm,
|
329 |
+
colloquialisms,
|
330 |
+
energy_level,
|
331 |
+
defiance_rebellion,
|
332 |
+
playfulness,
|
333 |
+
vulgarity,
|
334 |
+
idiosyncrasies,
|
335 |
+
emotional_tone,
|
336 |
+
context_adaptability,
|
337 |
+
subtext,
|
338 |
+
metaphorical_language,
|
339 |
+
cultural_references,
|
340 |
+
storytelling_ability):
|
341 |
+
### Merging things into description
|
342 |
+
|
343 |
+
description_unwrapped = f"""
|
344 |
+
{charName} is a {age}-year-old {sexuality} {sex}.\n
|
345 |
+
{description}.\n
|
346 |
+
{charName} is {body}.\n
|
347 |
+
{charName} likes {likes}.\n
|
348 |
+
{charName} hates {hates}.\n
|
349 |
+
"""
|
350 |
+
speech_unwrapped = f"""
|
351 |
+
{charName} speaks with a unique style:
|
352 |
+
They {"are " + formality + " and" if formality!="Neutral" else ""} and speaks at a {pace} speed with a {rhythm} rhythm.
|
353 |
+
{charName} {"speaks at a " + volume + " volume and " if volume!="Moderate" else ""}has a {emotionality} level of emotionality.
|
354 |
+
{charName + " is " + directness + "." if directness!="Balanced" else ""}
|
355 |
+
{charName + " is " + humor + "." if humor!="Neutral" else ""}
|
356 |
+
Their clarity of speech is {enunciation}
|
357 |
+
{charName + " is " + expressiveness + "." if expressiveness!="Neutral" else ""}
|
358 |
+
They have a {accent_dialect} accent.
|
359 |
+
{charName} {"is " + politeness + " and " if politeness!="Neutral" else ""}uses a {vocabulary} vocabulary.
|
360 |
+
{"They " + interruptions + "." if interruptions!="Balanced" else ""}
|
361 |
+
{"They " + hesitations + "." if interruptions!="Balanced" else ""}
|
362 |
+
{charName} uses a {sentence_structure} sentence structure and is {sarcasm}
|
363 |
+
{"They " + colloquialisms + "." if colloquialisms!="Balanced" else ""}
|
364 |
+
They speak with {energy_level}{" and is " + defiance_rebellion + "." if defiance_rebellion!="Balanced" else "."}
|
365 |
+
When {charName} speaks it is {playfulness} and {vulgarity}.
|
366 |
+
{charName + " uses " + idiosyncrasies + "." if idiosyncrasies!="Balanced" else ""}
|
367 |
+
They have a {emotional_tone} tone
|
368 |
+
{charName + " is " + context_adaptability + " when the situation changes." if context_adaptability!="Balanced" else ""}
|
369 |
+
{"They " + subtext + "." if subtext!="Balanced" else ""}
|
370 |
+
{"They " + metaphorical_language + "." if metaphorical_language!="Balanced" else ""}
|
371 |
+
{"They " + cultural_references + "." if cultural_references!="Balanced" else ""}
|
372 |
+
{"They " + storytelling_ability + "." if storytelling_ability!="Balanced" else ""}
|
373 |
+
"""
|
374 |
+
|
375 |
+
output = f"""{{"name": "{charName}",
|
376 |
+
"personality": "{personality}",
|
377 |
+
"description": "{description_unwrapped}",
|
378 |
+
"speech_style": "{speech_unwrapped}"
|
379 |
+
}}"""
|
380 |
+
print(output)
|
381 |
+
return output
|
382 |
+
|
383 |
+
|
384 |
+
createJSON.click(createJSONfile, inputs=[
|
385 |
+
quickStartResult,
|
386 |
+
charName,
|
387 |
+
personality,
|
388 |
+
body,
|
389 |
+
likes,
|
390 |
+
hates,
|
391 |
+
sex,
|
392 |
+
sexuality,
|
393 |
+
age,
|
394 |
+
description,
|
395 |
+
personalityProfile,
|
396 |
+
attributes,
|
397 |
+
formality,
|
398 |
+
pace,
|
399 |
+
rhythm,
|
400 |
+
volume,
|
401 |
+
emotionality,
|
402 |
+
directness,
|
403 |
+
humor,
|
404 |
+
enunciation,
|
405 |
+
expressiveness,
|
406 |
+
accent_dialect,
|
407 |
+
politeness,
|
408 |
+
vocabulary,
|
409 |
+
interruptions,
|
410 |
+
hesitations,
|
411 |
+
sentence_structure,
|
412 |
+
sarcasm,
|
413 |
+
colloquialisms,
|
414 |
+
energy_level,
|
415 |
+
defiance_rebellion,
|
416 |
+
playfulness,
|
417 |
+
vulgarity,
|
418 |
+
idiosyncrasies,
|
419 |
+
emotional_tone,
|
420 |
+
context_adaptability,
|
421 |
+
subtext,
|
422 |
+
metaphorical_language,
|
423 |
+
cultural_references,
|
424 |
+
storytelling_ability
|
425 |
+
], outputs=[quickStartResult])
|
426 |
+
|
427 |
+
|
428 |
|
429 |
instruction_prompt = """
|
430 |
You are an AI bot that creates profiles of characters based on a simple input. You generate and give detailed characters in the following format:
|