mecoffey commited on
Commit
968959a
·
1 Parent(s): a0f1f68

Added stats generation through LM

Browse files
Files changed (1) hide show
  1. app.py +50 -28
app.py CHANGED
@@ -11,22 +11,58 @@ pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", t
11
  DESC_SYSTEM_PROMPT = (
12
  "Write a description of a fantasy character based on the user prompt"
13
  "Include only the following items; Fantasy race, height, build, eye color, hair color/cut, clothing, notable physical features"
 
14
  )
15
  BACK_SYSTEM_PROMPT = (
16
- "Write a short synopsis of what the character has been through"
17
- "Keep each part short and fitting for a fantasy world normal person"
18
  "Include one line about what the character is thinking or doing right now."
 
19
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- ## Need to change this to combine the prompt and instrctions into a list of functions for the model to run.
22
  @spaces.GPU
23
  def char_description(prompt):
 
24
  prompt1 = f"{DESC_SYSTEM_PROMPT}\n\nCharacter Description: {prompt}\n\nDescribe:"
25
  output1 = pipe(prompt1, return_full_text=False, max_new_tokens=256)
26
  prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {prompt}\n\nDescribe:"
27
  output2 = pipe(prompt2, return_full_text=False, max_new_tokens=256)
28
- return output1,output2[0]["generated_text"].strip()
 
29
 
 
30
  def rand_char_description():
31
  input_file = open('core_races.txt', 'r')
32
  races = input_file.readline()
@@ -35,26 +71,11 @@ def rand_char_description():
35
  output1 = pipe(prompt1, return_full_text=False, max_new_tokens=256)
36
  prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {rand_race}\n\nDescribe:"
37
  output2 = pipe(prompt2, return_full_text=False, max_new_tokens=256)
38
- return output1,output2[0]["generated_text"].strip()
39
-
40
- #if the prompt is blank, use random number to choose a race and class from lists. The lists will only
41
- # include the most common of each. This will be fed in as the user prompt in leiu of a real one.
42
-
43
- # Function: combine prompt with a system prompt for the character description.
44
- # "system prompt = (Describe the physical characteristics of the Character requested) user prompt = (user_prompt)"
45
-
46
- # Function: use the description and prompt to generate stats. May need a function per stat. Or one function we can call
47
- # 6 times. Or we may leave this random. Maybe just have the model give a 1-10 rating of each skill based on the description
48
- # generated and then double it.
49
-
50
- # Function: use the description, prompt, and stats to generate backstory.
51
-
52
- # Function: use python to get DC and random advantage checks from lists.
53
 
54
- # change btn.click to map to those functions.
55
- # Maybe wrap them all into a single function with if/then logic to get all the way through the task.
56
 
57
- # add disadvantage in bard stats?
58
 
59
  ##UI is fine as-is
60
  with gr.Blocks() as demo:
@@ -72,12 +93,12 @@ with gr.Blocks() as demo:
72
  with gr.Row():
73
 
74
  with gr.Column(scale = 0):
75
- str = gr.Textbox(value = lambda:random.randint(1,20), label = "Strength", interactive = False)
76
- dex = gr.Textbox(value = lambda:random.randint(1,20), label = "Dexterity", interactive = False)
77
- con = gr.Textbox(value = lambda:random.randint(1,20), label = "Constitution", interactive = False)
78
- int = gr.Textbox(value = lambda:random.randint(1,20), label = "Intelligence", interactive = False)
79
- wis = gr.Textbox(value = lambda:random.randint(1,20), label = "Wisdom", interactive = False)
80
- char = gr.Textbox(value = lambda:random.randint(1,20), label = "Charisma", interactive = False)
81
 
82
  with gr.Column(scale = 2):
83
  text_out1 = gr.Textbox(label = "Description")
@@ -98,6 +119,7 @@ with gr.Blocks() as demo:
98
  with gr.Row():
99
  dcs = gr.Textbox(label = "DC to Smash")
100
  prefs = gr.Textbox(label = "Advantage if:")
 
101
 
102
 
103
  # Need to add export feature.
 
11
  DESC_SYSTEM_PROMPT = (
12
  "Write a description of a fantasy character based on the user prompt"
13
  "Include only the following items; Fantasy race, height, build, eye color, hair color/cut, clothing, notable physical features"
14
+ "Do not describe any mannerisms or activities."
15
  )
16
  BACK_SYSTEM_PROMPT = (
17
+ "Write a short timeline for this character"
18
+ "Keep each part short and fitting for a background character in a fantasy world."
19
  "Include one line about what the character is thinking or doing right now."
20
+ "Do not include any descriptions of physical features."
21
  )
22
+ STAT_SYSTEM_PROMPT = (
23
+ "give a single whole integer between 2 and 12 that reflects how proficient is a skill the described character is for this character's stat of:"
24
+ )
25
+
26
+ strength = ''
27
+ dexterity = ''
28
+ constitution = ''
29
+ intelligence = ''
30
+ wisdom = ''
31
+ charisma = ''
32
+
33
+ @spaces.GPU
34
+ def stats():
35
+ global strength
36
+ strength_prompt = f"{STAT_SYSTEM_PROMPT} Strength"
37
+ strength = pipe(strength_prompt, return_full_text=False)
38
+ global dexterity
39
+ dexterity_prompt = f"{STAT_SYSTEM_PROMPT} Dexterity"
40
+ dexterity = int(pipe(dexterity_prompt, return_full_text=False))
41
+ global constitution
42
+ constitution_prompt = f"{STAT_SYSTEM_PROMPT} Constitution"
43
+ constitution = int(pipe(constitution_prompt, return_full_text=False))
44
+ global intelligence
45
+ intelligence_prompt = f"{STAT_SYSTEM_PROMPT} Intelligence"
46
+ intelligence = int(pipe(intelligence_prompt, return_full_text=False))
47
+ global wisdom
48
+ wisdom_prompt = f"{STAT_SYSTEM_PROMPT} Wisdom"
49
+ wisdom = int(pipe(wisdom_prompt, return_full_text=False))
50
+ global charisma
51
+ charisma_prompt = f"{STAT_SYSTEM_PROMPT} Charisma"
52
+ charisma = int(pipe(charisma_prompt, return_full_text=False))
53
+
54
 
 
55
  @spaces.GPU
56
  def char_description(prompt):
57
+
58
  prompt1 = f"{DESC_SYSTEM_PROMPT}\n\nCharacter Description: {prompt}\n\nDescribe:"
59
  output1 = pipe(prompt1, return_full_text=False, max_new_tokens=256)
60
  prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {prompt}\n\nDescribe:"
61
  output2 = pipe(prompt2, return_full_text=False, max_new_tokens=256)
62
+ stats
63
+ return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
64
 
65
+ @spaces.GPU
66
  def rand_char_description():
67
  input_file = open('core_races.txt', 'r')
68
  races = input_file.readline()
 
71
  output1 = pipe(prompt1, return_full_text=False, max_new_tokens=256)
72
  prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {rand_race}\n\nDescribe:"
73
  output2 = pipe(prompt2, return_full_text=False, max_new_tokens=256)
74
+ stats
75
+ return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
 
 
77
 
78
+ # need to add bard stats generation.
79
 
80
  ##UI is fine as-is
81
  with gr.Blocks() as demo:
 
93
  with gr.Row():
94
 
95
  with gr.Column(scale = 0):
96
+ stre_box = gr.Textbox(value = strength, label = "Strength", interactive = False)
97
+ dex_box = gr.Textbox(value = dexterity, label = "Dexterity", interactive = False)
98
+ con_box = gr.Textbox(value = constitution, label = "Constitution", interactive = False)
99
+ intl_box = gr.Textbox(value = intelligence, label = "Intelligence", interactive = False)
100
+ wis_box = gr.Textbox(value = wisdom, label = "Wisdom", interactive = False)
101
+ char_box = gr.Textbox(value = charisma, label = "Charisma", interactive = False)
102
 
103
  with gr.Column(scale = 2):
104
  text_out1 = gr.Textbox(label = "Description")
 
119
  with gr.Row():
120
  dcs = gr.Textbox(label = "DC to Smash")
121
  prefs = gr.Textbox(label = "Advantage if:")
122
+ icks = gr.Textbox(label = "Disdvantage if:")
123
 
124
 
125
  # Need to add export feature.