applied stat generation functions to all stats
Browse files
app.py
CHANGED
|
@@ -32,6 +32,7 @@ hp = ''
|
|
| 32 |
smash = ''
|
| 33 |
pref_traits = ''
|
| 34 |
ick_traits = ''
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
|
|
@@ -42,20 +43,6 @@ def char_description(prompt):
|
|
| 42 |
output1 = pipe(prompt1, return_full_text=False, max_new_tokens=256)
|
| 43 |
prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {prompt}\n\nDescribe:"
|
| 44 |
output2 = pipe(prompt2, return_full_text=False, max_new_tokens=256)
|
| 45 |
-
global ac
|
| 46 |
-
ac = random.randint(2,14)
|
| 47 |
-
global hp
|
| 48 |
-
hp = constitution + random.randint(1,6)
|
| 49 |
-
global smash
|
| 50 |
-
smash = random.randint(1,30)
|
| 51 |
-
input_file = open('traits.txt', 'r')
|
| 52 |
-
traits = input_file.readline()
|
| 53 |
-
global pref_traits
|
| 54 |
-
picks = int(random.randint(1,3))
|
| 55 |
-
pref_traits = random.choice(traits, k=picks)
|
| 56 |
-
global ick_traits
|
| 57 |
-
picks = int(random.randint(1,3))
|
| 58 |
-
ick_traits = random.choice(traits, k=picks)
|
| 59 |
return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
|
| 60 |
|
| 61 |
@spaces.GPU
|
|
@@ -84,6 +71,27 @@ def stats_gen():
|
|
| 84 |
charisma = random.randint(2,12)
|
| 85 |
return strength, dexterity, constitution, intelligence, wisdom, charisma
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
##UI is fine as-is
|
| 89 |
with gr.Blocks() as demo:
|
|
@@ -98,7 +106,7 @@ with gr.Blocks() as demo:
|
|
| 98 |
btn = gr.Button("Generate")
|
| 99 |
rand = gr.Button("Random")
|
| 100 |
|
| 101 |
-
with gr.Row(
|
| 102 |
|
| 103 |
with gr.Column(scale = 0):
|
| 104 |
stre_box = gr.Textbox(value = strength, label = "Strength", interactive = False)
|
|
@@ -108,18 +116,21 @@ with gr.Blocks() as demo:
|
|
| 108 |
wis_box = gr.Textbox(value = wisdom, label = "Wisdom", interactive = False)
|
| 109 |
char_box = gr.Textbox(value = charisma, label = "Charisma", interactive = False)
|
| 110 |
btn.click(fn = stats_gen, outputs = [stre_box, dex_box, con_box, intl_box, wis_box, char_box])
|
|
|
|
| 111 |
|
| 112 |
with gr.Column(scale = 2):
|
| 113 |
text_out1 = gr.Textbox(label = "Description")
|
| 114 |
text_out2 = gr.Textbox(label = "Backstory")
|
| 115 |
btn.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
|
| 116 |
-
rand.click(fn = rand_char_description,
|
| 117 |
|
| 118 |
|
| 119 |
with gr.Column(scale = 0):
|
| 120 |
ac_box = gr.Textbox(value = ac, label = "AC", interactive = False)
|
| 121 |
hp_box = gr.Textbox(value = hp, label = "HP", interactive = False)
|
| 122 |
speed_box = gr.Textbox(value = "25 ft", label = "Speed", interactive = False)
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
with gr.Row():
|
|
@@ -129,6 +140,8 @@ with gr.Blocks() as demo:
|
|
| 129 |
dcs = gr.Textbox(value = smash, label = "DC to Smash")
|
| 130 |
prefs = gr.Textbox(value = pref_traits, label = "Advantage if:")
|
| 131 |
icks = gr.Textbox(value = ick_traits, label = "Disdvantage if:")
|
|
|
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
|
|
|
|
| 32 |
smash = ''
|
| 33 |
pref_traits = ''
|
| 34 |
ick_traits = ''
|
| 35 |
+
speed = ''
|
| 36 |
|
| 37 |
|
| 38 |
|
|
|
|
| 43 |
output1 = pipe(prompt1, return_full_text=False, max_new_tokens=256)
|
| 44 |
prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {prompt}\n\nDescribe:"
|
| 45 |
output2 = pipe(prompt2, return_full_text=False, max_new_tokens=256)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
|
| 47 |
|
| 48 |
@spaces.GPU
|
|
|
|
| 71 |
charisma = random.randint(2,12)
|
| 72 |
return strength, dexterity, constitution, intelligence, wisdom, charisma
|
| 73 |
|
| 74 |
+
def stats_gen_2():
|
| 75 |
+
global ac
|
| 76 |
+
ac = random.randint(2,14)
|
| 77 |
+
global hp
|
| 78 |
+
hp = constitution + random.randint(1,6)
|
| 79 |
+
global speed
|
| 80 |
+
speed = '25 ft'
|
| 81 |
+
return ac, hp, speed
|
| 82 |
+
|
| 83 |
+
def bard_stats_gen():
|
| 84 |
+
global smash
|
| 85 |
+
smash = random.randint(1,30)
|
| 86 |
+
input_file = open('traits.txt', 'r')
|
| 87 |
+
traits = input_file.readline()
|
| 88 |
+
global pref_traits
|
| 89 |
+
picks = int(random.randint(1,3))
|
| 90 |
+
pref_traits = random.choice(traits, k=picks)
|
| 91 |
+
global ick_traits
|
| 92 |
+
picks = int(random.randint(1,3))
|
| 93 |
+
ick_traits = random.choice(traits, k=picks)
|
| 94 |
+
return smash, pref_traits, ick_traits
|
| 95 |
|
| 96 |
##UI is fine as-is
|
| 97 |
with gr.Blocks() as demo:
|
|
|
|
| 106 |
btn = gr.Button("Generate")
|
| 107 |
rand = gr.Button("Random")
|
| 108 |
|
| 109 |
+
with gr.Row():
|
| 110 |
|
| 111 |
with gr.Column(scale = 0):
|
| 112 |
stre_box = gr.Textbox(value = strength, label = "Strength", interactive = False)
|
|
|
|
| 116 |
wis_box = gr.Textbox(value = wisdom, label = "Wisdom", interactive = False)
|
| 117 |
char_box = gr.Textbox(value = charisma, label = "Charisma", interactive = False)
|
| 118 |
btn.click(fn = stats_gen, outputs = [stre_box, dex_box, con_box, intl_box, wis_box, char_box])
|
| 119 |
+
rand.click(fn = stats_gen, outputs = [stre_box, dex_box, con_box, intl_box, wis_box, char_box])
|
| 120 |
|
| 121 |
with gr.Column(scale = 2):
|
| 122 |
text_out1 = gr.Textbox(label = "Description")
|
| 123 |
text_out2 = gr.Textbox(label = "Backstory")
|
| 124 |
btn.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
|
| 125 |
+
rand.click(fn = rand_char_description, outputs = [text_out1, text_out2])
|
| 126 |
|
| 127 |
|
| 128 |
with gr.Column(scale = 0):
|
| 129 |
ac_box = gr.Textbox(value = ac, label = "AC", interactive = False)
|
| 130 |
hp_box = gr.Textbox(value = hp, label = "HP", interactive = False)
|
| 131 |
speed_box = gr.Textbox(value = "25 ft", label = "Speed", interactive = False)
|
| 132 |
+
btn.click(fn = stats_gen_2, outputs = [ac_box, hp_box, speed_box])
|
| 133 |
+
rand.click(fn = stats_gen_2, outputs = [ac_box, hp_box, speed_box])
|
| 134 |
|
| 135 |
|
| 136 |
with gr.Row():
|
|
|
|
| 140 |
dcs = gr.Textbox(value = smash, label = "DC to Smash")
|
| 141 |
prefs = gr.Textbox(value = pref_traits, label = "Advantage if:")
|
| 142 |
icks = gr.Textbox(value = ick_traits, label = "Disdvantage if:")
|
| 143 |
+
btn.click(fn = bard_stats_gen, outputs = [dcs, prefs, icks])
|
| 144 |
+
rand.click(fn = bard_stats_gen, outputs = [dcs, prefs, icks])
|
| 145 |
|
| 146 |
|
| 147 |
|