Spaces:
Runtime error
Runtime error
Update test.py
Browse files+ psycho profile
+ test function
+ better speech profile
test.py
CHANGED
@@ -3,6 +3,8 @@ import json
|
|
3 |
import time
|
4 |
#Jup1t3R!
|
5 |
|
|
|
|
|
6 |
### Good results with lmsys_vicuna-13b-v1.1 4-bit>> ~150s
|
7 |
### Good results with lmsys_vicuna-7b-v1.1 4-bit>> ~75s
|
8 |
|
@@ -15,6 +17,8 @@ URI = f'http://{HOST}/api/v1/generate'
|
|
15 |
INSTRUCTION_KEY = "### User:"
|
16 |
RESPONSE_KEY = "### Assistant:"
|
17 |
|
|
|
|
|
18 |
preprompt = f"""
|
19 |
{INSTRUCTION_KEY}
|
20 |
You are a professional writer, novelist, and character creator. You are extremely knowledgeable in the art of character creation. You should provide the details of a character as requested by the User. Only output the exact answer. When given choices you must pick one and only one. You should not add additional context. You should be concise. You should follow the exact format requested. Do not add any additional information or context. This a fictional character, totally imagined and created by you. It is not a real person.
|
@@ -228,16 +232,14 @@ def getAllSpeech(general, name):
|
|
228 |
break
|
229 |
if was_found==False:
|
230 |
traits_dict['speech'][key] = "neutral"
|
231 |
-
print(f"
|
232 |
-
print(f"!!!!!!!! from the prompt: {prompt}")
|
233 |
|
234 |
def unwrapText():
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
# """
|
241 |
speech_unwrapped = f"""
|
242 |
{traits_dict['name']} speaks with a unique style:
|
243 |
They {"are " + traits_dict['speech']['formality'] + " and" if traits_dict['speech']['formality']!="neutral" else ""} speak at a {traits_dict['speech']['pace']} speed with a {traits_dict['speech']['rhythm']} rhythm.
|
@@ -250,8 +252,7 @@ They have a {traits_dict['speech']['accent']} accent.
|
|
250 |
{traits_dict['name']} {"is " + traits_dict['speech']['politeness'] + " and " if traits_dict['speech']['politeness']!="neutral" else ""}uses a {traits_dict['speech']['vocabulary']} vocabulary.
|
251 |
{"They " + traits_dict['speech']['interruptions'] + "." if traits_dict['speech']['interruptions']!="balanced" else ""}
|
252 |
{"They " + traits_dict['speech']['hesitations'] + "." if traits_dict['speech']['interruptions']!="balanced" else ""}
|
253 |
-
{traits_dict['name']} uses a {traits_dict['speech']['sentence_structure']} sentence structure and is {traits_dict['speech']['sarcasm']}
|
254 |
-
{"They " + traits_dict['speech']['colloquialisms'] + "." if traits_dict['speech']['colloquialisms']!="balanced" else ""}
|
255 |
They speak with {traits_dict['speech']['energy_level']}{" and is " + traits_dict['speech']['defiance/rebellion'] + "." if traits_dict['speech']['defiance/rebellion']!="balanced" else "."}
|
256 |
When {traits_dict['name']} speaks it is {traits_dict['speech']['playfulness']} and {traits_dict['speech']['vulgarity']}.
|
257 |
{traits_dict['name'] + " uses " + traits_dict['speech']['idiosyncrasies'] + "." if traits_dict['speech']['idiosyncrasies']!="balanced" else ""}
|
@@ -262,15 +263,54 @@ They have a {traits_dict['speech']['emotional_tone']} tone
|
|
262 |
{"They " + traits_dict['speech']['cultural_references'] + "." if traits_dict['speech']['cultural_references']!="balanced" else ""}
|
263 |
{"They " + traits_dict['speech']['storytelling_ability'] + "." if traits_dict['speech']['storytelling_ability']!="balanced" else ""}
|
264 |
"""
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
if __name__ == '__main__':
|
268 |
-
##TEST
|
269 |
-
# getAllSpeech("Roger Rabbit is an energetic, funny, clever, adventurous, and optimistic rabbit. He hates being ignored or laughed at and dislikes sadness and injustice. Roger enjoys listening to jazz music, eating carrots, playing the piano, and solving puzzles. His personality is charming, witty, and charismatic with his short, round body covered in red fur and large ears. As a male rabbit, he is heterosexual and ten years old.","Roger Rabbit")
|
270 |
-
# print(traits_dict)
|
271 |
-
##END TEST
|
272 |
first_time = time.time()
|
273 |
-
character = "a comedian based on George Carlin named Bob"
|
274 |
cleaned_data = remove_after_first_brace(getTraits(character))
|
275 |
traits_dict = json.loads(cleaned_data)
|
276 |
for key, value in traits_dict.items():
|
@@ -283,17 +323,16 @@ if __name__ == '__main__':
|
|
283 |
traits_dict['sexuality'] = remove_non_letters(getSexuality(character))
|
284 |
traits_dict['age'] = remove_non_numbers(getAge(character))
|
285 |
traits_dict['general'] = getGeneralDescription(traits_dict, traits_dict['name'])
|
286 |
-
|
287 |
getAllSpeech(traits_dict['general'], traits_dict['name'])
|
288 |
unwrapText()
|
289 |
-
# print(getSpeech(traits_dict))
|
290 |
-
# traits_dict['description'] = (getGeneralDescription(character, traits_dict))
|
291 |
last_time = time.time()
|
292 |
total_time = round(last_time - first_time, 2)
|
293 |
print(f"Total time taken >> {total_time}")
|
294 |
print(" ################# OUTPUT #################")
|
295 |
for key, value in traits_dict.items():
|
296 |
print(f"{key}: {value}")
|
|
|
297 |
|
298 |
|
299 |
|
|
|
3 |
import time
|
4 |
#Jup1t3R!
|
5 |
|
6 |
+
### Great results with lmsys_vicuna-13b-v1.1 8-bit>> ~425s
|
7 |
+
### Great results with lmsys_vicuna-7b-v1.1 16-bit>> ~90s
|
8 |
### Good results with lmsys_vicuna-13b-v1.1 4-bit>> ~150s
|
9 |
### Good results with lmsys_vicuna-7b-v1.1 4-bit>> ~75s
|
10 |
|
|
|
17 |
INSTRUCTION_KEY = "### User:"
|
18 |
RESPONSE_KEY = "### Assistant:"
|
19 |
|
20 |
+
character = "Holden Caulfield"
|
21 |
+
|
22 |
preprompt = f"""
|
23 |
{INSTRUCTION_KEY}
|
24 |
You are a professional writer, novelist, and character creator. You are extremely knowledgeable in the art of character creation. You should provide the details of a character as requested by the User. Only output the exact answer. When given choices you must pick one and only one. You should not add additional context. You should be concise. You should follow the exact format requested. Do not add any additional information or context. This a fictional character, totally imagined and created by you. It is not a real person.
|
|
|
232 |
break
|
233 |
if was_found==False:
|
234 |
traits_dict['speech'][key] = "neutral"
|
235 |
+
print(f">>> FAIL, setting to 'neutral'")
|
|
|
236 |
|
237 |
def unwrapText():
|
238 |
+
description_unwrapped = f"""
|
239 |
+
{traits_dict['name']} is a {traits_dict['age']}-year-old {traits_dict['sexuality']} {traits_dict['sex']}.{traits_dict['general']} {traits_dict['name']} likes {traits_dict['likes']}. {traits_dict['name']} hates {traits_dict['hates']}.
|
240 |
+
"""
|
241 |
+
traits_dict['description'] = description_unwrapped.strip('\n')
|
242 |
+
|
|
|
243 |
speech_unwrapped = f"""
|
244 |
{traits_dict['name']} speaks with a unique style:
|
245 |
They {"are " + traits_dict['speech']['formality'] + " and" if traits_dict['speech']['formality']!="neutral" else ""} speak at a {traits_dict['speech']['pace']} speed with a {traits_dict['speech']['rhythm']} rhythm.
|
|
|
252 |
{traits_dict['name']} {"is " + traits_dict['speech']['politeness'] + " and " if traits_dict['speech']['politeness']!="neutral" else ""}uses a {traits_dict['speech']['vocabulary']} vocabulary.
|
253 |
{"They " + traits_dict['speech']['interruptions'] + "." if traits_dict['speech']['interruptions']!="balanced" else ""}
|
254 |
{"They " + traits_dict['speech']['hesitations'] + "." if traits_dict['speech']['interruptions']!="balanced" else ""}
|
255 |
+
{traits_dict['name']} uses a {traits_dict['speech']['sentence_structure']} sentence structure and is {traits_dict['speech']['sarcasm']}{" They " + traits_dict['speech']['colloquialisms'] + "." if traits_dict['speech']['colloquialisms']!="balanced" else ""}
|
|
|
256 |
They speak with {traits_dict['speech']['energy_level']}{" and is " + traits_dict['speech']['defiance/rebellion'] + "." if traits_dict['speech']['defiance/rebellion']!="balanced" else "."}
|
257 |
When {traits_dict['name']} speaks it is {traits_dict['speech']['playfulness']} and {traits_dict['speech']['vulgarity']}.
|
258 |
{traits_dict['name'] + " uses " + traits_dict['speech']['idiosyncrasies'] + "." if traits_dict['speech']['idiosyncrasies']!="balanced" else ""}
|
|
|
263 |
{"They " + traits_dict['speech']['cultural_references'] + "." if traits_dict['speech']['cultural_references']!="balanced" else ""}
|
264 |
{"They " + traits_dict['speech']['storytelling_ability'] + "." if traits_dict['speech']['storytelling_ability']!="balanced" else ""}
|
265 |
"""
|
266 |
+
traits_dict['speech_unwrapped'] = speech_unwrapped
|
267 |
+
print(f"{speech_unwrapped} {description_unwrapped}")
|
268 |
+
|
269 |
+
prompt = f"""
|
270 |
+
{INSTRUCTION_KEY} Please take this description of a character's speaking pattern, clean it up, and make sure the description is clear: {speech_unwrapped}
|
271 |
+
{RESPONSE_KEY} Sure! Here is the revised description:
|
272 |
+
"""
|
273 |
+
print(f"Correcting speech profile.")
|
274 |
+
response = run(prompt, 250)
|
275 |
+
traits_dict['speech_unwrapped'] = response
|
276 |
|
277 |
+
def getPsychProfile(general):
|
278 |
+
prompt = f"""
|
279 |
+
{preprompt}
|
280 |
+
{general}
|
281 |
+
Based on your understanding of this character, analyze their psychological profile using the standard profiles:
|
282 |
+
Myers-Briggs Type Indicator (MBTI): Introverted/Extraverted, Sensing/Intuitive, Thinking/Feeling, Judging/Perceiving.
|
283 |
+
Enneagram: main type, wing, and instinctual variant (self-preservation/sp, social/so, or sexual/sx).
|
284 |
+
Enneagram Tritype: two additional types from different centers of intelligence.
|
285 |
+
Socionics: similar to MBTI, identify the character's personality type.
|
286 |
+
Global 5/SLOAN: Reserved/Social, Calm/Limbic, Organized/Unstructured, Accommodating/Egocentric, Non-Curious/Inquisitive.
|
287 |
+
Tell me your analysis in this exact format: MBTI - Enneagram - Instinctual Variant - Tritype - Socionics - SLOAN. For example: INTJ - 3w4 - sp/sx - 358 - LIE - RCOEI. Do not explain or add other text or context.
|
288 |
+
{RESPONSE_KEY} Sure! Based on the description of this character, and without any explanation, their psychological profile is
|
289 |
+
"""
|
290 |
+
print(f"Getting psych profile.")
|
291 |
+
response = run(prompt, 120)
|
292 |
+
return response.strip('"')
|
293 |
+
|
294 |
+
def test():
|
295 |
+
prompt = f"""
|
296 |
+
{INSTRUCTION_KEY}
|
297 |
+
{traits_dict['speech_unwrapped']}
|
298 |
+
Use this information and your writing and creative experience to create a sample dialogue between {traits_dict['name']} and a fictional neutral character named John. {traits_dict['name']} must speak exactly as specified. Words chosen, topic discussed, grammar, sentence structure, and vocabulary should all be considered when shaping this conversation.
|
299 |
+
{RESPONSE_KEY}
|
300 |
+
"""
|
301 |
+
response = run(prompt, 350)
|
302 |
+
print(f"*1* {response} ***")
|
303 |
+
preprompt = prompt + response
|
304 |
+
prompt = f"""
|
305 |
+
{INSTRUCTION_KEY}
|
306 |
+
Using the speaking style described, revise that conversation to best match how {traits_dict['name']} would really speak
|
307 |
+
{RESPONSE_KEY}
|
308 |
+
"""
|
309 |
+
response = run(preprompt + prompt, 500)
|
310 |
+
print(f"*2* {response} ***")
|
311 |
+
|
312 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
313 |
first_time = time.time()
|
|
|
314 |
cleaned_data = remove_after_first_brace(getTraits(character))
|
315 |
traits_dict = json.loads(cleaned_data)
|
316 |
for key, value in traits_dict.items():
|
|
|
323 |
traits_dict['sexuality'] = remove_non_letters(getSexuality(character))
|
324 |
traits_dict['age'] = remove_non_numbers(getAge(character))
|
325 |
traits_dict['general'] = getGeneralDescription(traits_dict, traits_dict['name'])
|
326 |
+
traits_dict['psych'] = getPsychProfile(traits_dict['general'])
|
327 |
getAllSpeech(traits_dict['general'], traits_dict['name'])
|
328 |
unwrapText()
|
|
|
|
|
329 |
last_time = time.time()
|
330 |
total_time = round(last_time - first_time, 2)
|
331 |
print(f"Total time taken >> {total_time}")
|
332 |
print(" ################# OUTPUT #################")
|
333 |
for key, value in traits_dict.items():
|
334 |
print(f"{key}: {value}")
|
335 |
+
test()
|
336 |
|
337 |
|
338 |
|