cosmetic changes, changed info generation to improve wait time.
Browse files
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: NPCGenerator
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.17.3
|
| 8 |
python_version: '3.12'
|
|
|
|
| 1 |
---
|
| 2 |
title: NPCGenerator
|
| 3 |
+
emoji: ⚔️
|
| 4 |
+
colorFrom: grey
|
| 5 |
+
colorTo: grey
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.17.3
|
| 8 |
python_version: '3.12'
|
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import random
|
| 3 |
import spaces
|
| 4 |
import torch
|
| 5 |
-
from transformers import
|
| 6 |
|
| 7 |
|
| 8 |
|
|
@@ -10,12 +10,14 @@ pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", t
|
|
| 10 |
|
| 11 |
DESC_SYSTEM_PROMPT = (
|
| 12 |
"Write a description of a fantasy character based on the user prompt"
|
| 13 |
-
"
|
| 14 |
-
"
|
|
|
|
| 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 |
)
|
|
@@ -29,37 +31,33 @@ constitution = ''
|
|
| 29 |
intelligence = ''
|
| 30 |
wisdom = ''
|
| 31 |
charisma = ''
|
|
|
|
| 32 |
|
| 33 |
@spaces.GPU
|
| 34 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -68,10 +66,27 @@ def rand_char_description():
|
|
| 68 |
races = input_file.readline()
|
| 69 |
rand_race = random.choice(races)
|
| 70 |
prompt1 = f"{DESC_SYSTEM_PROMPT}\n\nCharacter Description: {rand_race}\n\nDescribe:"
|
| 71 |
-
output1 = pipe(prompt1, return_full_text=False, max_new_tokens=
|
| 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=
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
|
| 76 |
|
| 77 |
|
|
@@ -81,7 +96,7 @@ def rand_char_description():
|
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
title = gr.HTML("<center><h1>NPC Generator</h1></center>")
|
| 83 |
description = gr.HTML("<center>For tabletop GMs when players ask for a description of random people in the tavern.</center>")
|
| 84 |
-
tags = gr.HTML("<center>| Backyard AI | Tiny Titan |
|
| 85 |
|
| 86 |
with gr.Row(equal_height = True):
|
| 87 |
with gr.Column(scale = 2):
|
|
@@ -104,11 +119,11 @@ with gr.Blocks() as demo:
|
|
| 104 |
text_out1 = gr.Textbox(label = "Description")
|
| 105 |
text_out2 = gr.Textbox(label = "Backstory")
|
| 106 |
btn.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
|
| 107 |
-
rand.click(fn = rand_char_description,inputs =
|
| 108 |
|
| 109 |
|
| 110 |
with gr.Column(scale = 0):
|
| 111 |
-
ac = gr.Textbox(value = lambda:random.randint(
|
| 112 |
speed = gr.Textbox(value = lambda:random.randint(10,30), label = "HP", interactive = False)
|
| 113 |
speed = gr.Textbox(value = lambda:"25 ft", label = "Speed", interactive = False)
|
| 114 |
|
|
|
|
| 2 |
import random
|
| 3 |
import spaces
|
| 4 |
import torch
|
| 5 |
+
from transformers import pipeline
|
| 6 |
|
| 7 |
|
| 8 |
|
|
|
|
| 10 |
|
| 11 |
DESC_SYSTEM_PROMPT = (
|
| 12 |
"Write a description of a fantasy character based on the user prompt"
|
| 13 |
+
"response Must include: fantasy Race, height, build, eye color, hair color, clothing."
|
| 14 |
+
"response may include: noticeable features such as scars, tattoos, jewelry, or expression"
|
| 15 |
+
"Response must not include any extraneous details."
|
| 16 |
)
|
| 17 |
BACK_SYSTEM_PROMPT = (
|
| 18 |
"Write a short timeline for this character"
|
| 19 |
"Keep each part short and fitting for a background character in a fantasy world."
|
| 20 |
+
"include things like occupations they have had, family ties, livelihood, or mannerisms."
|
| 21 |
"Include one line about what the character is thinking or doing right now."
|
| 22 |
"Do not include any descriptions of physical features."
|
| 23 |
)
|
|
|
|
| 31 |
intelligence = ''
|
| 32 |
wisdom = ''
|
| 33 |
charisma = ''
|
| 34 |
+
|
| 35 |
|
| 36 |
@spaces.GPU
|
| 37 |
+
def char_description(prompt):
|
| 38 |
+
|
| 39 |
+
prompt1 = f"{DESC_SYSTEM_PROMPT}\n\nCharacter Description: {prompt}\n\nDescribe:"
|
| 40 |
+
output1 = pipe(prompt1, return_full_text=False, max_new_tokens=128)
|
| 41 |
+
prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {prompt}\n\nDescribe:"
|
| 42 |
+
output2 = pipe(prompt2, return_full_text=False, max_new_tokens=128)
|
| 43 |
global strength
|
| 44 |
+
strength_prompt = f"{STAT_SYSTEM_PROMPT} Strength for {output1}"
|
| 45 |
strength = pipe(strength_prompt, return_full_text=False)
|
| 46 |
global dexterity
|
| 47 |
+
dexterity_prompt = f"{STAT_SYSTEM_PROMPT} Dexterity for {output1}"
|
| 48 |
dexterity = int(pipe(dexterity_prompt, return_full_text=False))
|
| 49 |
global constitution
|
| 50 |
+
constitution_prompt = f"{STAT_SYSTEM_PROMPT} Constitution for {output1}"
|
| 51 |
constitution = int(pipe(constitution_prompt, return_full_text=False))
|
| 52 |
global intelligence
|
| 53 |
+
intelligence_prompt = f"{STAT_SYSTEM_PROMPT} Intelligence for {output1}"
|
| 54 |
intelligence = int(pipe(intelligence_prompt, return_full_text=False))
|
| 55 |
global wisdom
|
| 56 |
+
wisdom_prompt = f"{STAT_SYSTEM_PROMPT} Wisdom for {output1}"
|
| 57 |
wisdom = int(pipe(wisdom_prompt, return_full_text=False))
|
| 58 |
global charisma
|
| 59 |
+
charisma_prompt = f"{STAT_SYSTEM_PROMPT} Charisma for {output1}"
|
| 60 |
charisma = int(pipe(charisma_prompt, return_full_text=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
|
| 62 |
|
| 63 |
@spaces.GPU
|
|
|
|
| 66 |
races = input_file.readline()
|
| 67 |
rand_race = random.choice(races)
|
| 68 |
prompt1 = f"{DESC_SYSTEM_PROMPT}\n\nCharacter Description: {rand_race}\n\nDescribe:"
|
| 69 |
+
output1 = pipe(prompt1, return_full_text=False, max_new_tokens=128)
|
| 70 |
prompt2 = f"{BACK_SYSTEM_PROMPT}\n\n{output1}\n\nUser prompt: {rand_race}\n\nDescribe:"
|
| 71 |
+
output2 = pipe(prompt2, return_full_text=False, max_new_tokens=128)
|
| 72 |
+
global strength
|
| 73 |
+
strength_prompt = f"{STAT_SYSTEM_PROMPT} Strength for {output1}"
|
| 74 |
+
strength = pipe(strength_prompt, return_full_text=False)
|
| 75 |
+
global dexterity
|
| 76 |
+
dexterity_prompt = f"{STAT_SYSTEM_PROMPT} Dexterity for {output1}"
|
| 77 |
+
dexterity = int(pipe(dexterity_prompt, return_full_text=False))
|
| 78 |
+
global constitution
|
| 79 |
+
constitution_prompt = f"{STAT_SYSTEM_PROMPT} Constitution for {output1}"
|
| 80 |
+
constitution = int(pipe(constitution_prompt, return_full_text=False))
|
| 81 |
+
global intelligence
|
| 82 |
+
intelligence_prompt = f"{STAT_SYSTEM_PROMPT} Intelligence for {output1}"
|
| 83 |
+
intelligence = int(pipe(intelligence_prompt, return_full_text=False))
|
| 84 |
+
global wisdom
|
| 85 |
+
wisdom_prompt = f"{STAT_SYSTEM_PROMPT} Wisdom for {output1}"
|
| 86 |
+
wisdom = int(pipe(wisdom_prompt, return_full_text=False))
|
| 87 |
+
global charisma
|
| 88 |
+
charisma_prompt = f"{STAT_SYSTEM_PROMPT} Charisma for {output1}"
|
| 89 |
+
charisma = int(pipe(charisma_prompt, return_full_text=False))
|
| 90 |
return output1[0]["generated_text"].strip(),output2[0]["generated_text"].strip()
|
| 91 |
|
| 92 |
|
|
|
|
| 96 |
with gr.Blocks() as demo:
|
| 97 |
title = gr.HTML("<center><h1>NPC Generator</h1></center>")
|
| 98 |
description = gr.HTML("<center>For tabletop GMs when players ask for a description of random people in the tavern.</center>")
|
| 99 |
+
tags = gr.HTML("<center>| Backyard AI | Tiny Titan |</center>")
|
| 100 |
|
| 101 |
with gr.Row(equal_height = True):
|
| 102 |
with gr.Column(scale = 2):
|
|
|
|
| 119 |
text_out1 = gr.Textbox(label = "Description")
|
| 120 |
text_out2 = gr.Textbox(label = "Backstory")
|
| 121 |
btn.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
|
| 122 |
+
rand.click(fn = rand_char_description,inputs = None, outputs = [text_out1, text_out2])
|
| 123 |
|
| 124 |
|
| 125 |
with gr.Column(scale = 0):
|
| 126 |
+
ac = gr.Textbox(value = lambda:random.randint(3,20), label = "AC", interactive = False)
|
| 127 |
speed = gr.Textbox(value = lambda:random.randint(10,30), label = "HP", interactive = False)
|
| 128 |
speed = gr.Textbox(value = lambda:"25 ft", label = "Speed", interactive = False)
|
| 129 |
|