mecoffey commited on
Commit
d9757ab
·
1 Parent(s): c26ddd7

Added pretrained model and system prompts. We have a brain peoplegit add app.py requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +52 -2
  2. requirements.txt +3 -1
app.py CHANGED
@@ -1,18 +1,63 @@
1
  import gradio as gr
2
  import random
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def char_description(prompt):
 
 
 
 
 
5
  output1 = "I see you asked for " + prompt + "!"
6
  output2 = "I cannot create " + prompt + " yet, because I do not have a brain."
7
  return output1, output2
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  with gr.Blocks() as demo:
10
  title = gr.HTML("<center><h1>NPC Generator</h1></center>")
11
  description = gr.HTML("<center>For tabletop GMs when players ask for a description of random people in the tavern.</center>")
12
  tags = gr.HTML("<center>| Backyard AI | Tiny Titan | Well Tuned |</center>")
 
13
  with gr.Row(equal_height = True):
14
  with gr.Column(scale = 2):
15
- text_in = gr.Textbox(label="What npc do you need?")
16
  with gr.Column(scale = 0):
17
  btn = gr.Button("Generate")
18
  rand = gr.Button("Random")
@@ -31,12 +76,14 @@ with gr.Blocks() as demo:
31
  text_out1 = gr.Textbox(label = "Description")
32
  text_out2 = gr.Textbox(label = "Backstory")
33
  btn.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
34
- rand.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
35
 
36
 
37
  with gr.Column(scale = 0):
38
  ac = gr.Textbox(value = lambda:random.randint(1,20), label = "AC", interactive = False)
 
39
  speed = gr.Textbox(value = lambda:"25 ft", label = "Speed", interactive = False)
 
40
 
41
  with gr.Row():
42
 
@@ -45,4 +92,7 @@ with gr.Blocks() as demo:
45
  dcs = gr.Textbox(label = "DC to Smash")
46
  prefs = gr.Textbox(label = "Advantage if:")
47
 
 
 
 
48
  demo.launch(theme = gr.themes.Monochrome())
 
1
  import gradio as gr
2
  import random
3
+ import spaces
4
+ import torch
5
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
6
 
7
+
8
+
9
+ pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v0.6", torch_dtype=torch.bfloat16, device_map="auto")
10
+
11
+ DESC_SYSTEM_PROMPT = (
12
+ "Write a description of a fantasy character based on the user prompt"
13
+ "Include only the following items; Race, height, build, eye color, hair color/cut, clothing, notable 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
+ output1 = f"{DESC_SYSTEM_PROMPT}\n\nCharacter Description: {prompt}\n\nDescribe:"
25
+ output2 = "I cannot create " + prompt + " yet, because I do not have a brain."
26
+ return output1, output2
27
+
28
+ def rand_char_description(prompt):
29
  output1 = "I see you asked for " + prompt + "!"
30
  output2 = "I cannot create " + prompt + " yet, because I do not have a brain."
31
  return output1, output2
32
 
33
+ #if the prompt is blank, use random number to choose a race and class from lists. The lists will only
34
+ # include the most common of each. This will be fed in as the user prompt in leiu of a real one.
35
+
36
+ # Function: combine prompt with a system prompt for the character description.
37
+ # "system prompt = (Describe the physical characteristics of the Character requested) user prompt = (user_prompt)"
38
+
39
+ # Function: use the description and prompt to generate stats. May need a function per stat. Or one function we can call
40
+ # 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
41
+ # generated and then double it.
42
+
43
+ # Function: use the description, prompt, and stats to generate backstory.
44
+
45
+ # Function: use python to get DC and random advantage checks from lists.
46
+
47
+ # change btn.click to map to those functions.
48
+ # Maybe wrap them all into a single function with if/then logic to get all the way through the task.
49
+
50
+ # add disadvantage in bard stats?
51
+
52
+ ##UI is fine as-is
53
  with gr.Blocks() as demo:
54
  title = gr.HTML("<center><h1>NPC Generator</h1></center>")
55
  description = gr.HTML("<center>For tabletop GMs when players ask for a description of random people in the tavern.</center>")
56
  tags = gr.HTML("<center>| Backyard AI | Tiny Titan | Well Tuned |</center>")
57
+
58
  with gr.Row(equal_height = True):
59
  with gr.Column(scale = 2):
60
+ text_in = gr.Textbox(label="What npc do you need?", placeholder = "An Orc Barkeep")
61
  with gr.Column(scale = 0):
62
  btn = gr.Button("Generate")
63
  rand = gr.Button("Random")
 
76
  text_out1 = gr.Textbox(label = "Description")
77
  text_out2 = gr.Textbox(label = "Backstory")
78
  btn.click(fn = char_description,inputs = text_in, outputs = [text_out1, text_out2])
79
+ rand.click(fn = rand_char_description,inputs = text_in, outputs = [text_out1, text_out2])
80
 
81
 
82
  with gr.Column(scale = 0):
83
  ac = gr.Textbox(value = lambda:random.randint(1,20), label = "AC", interactive = False)
84
+ speed = gr.Textbox(value = lambda:random.randint(10,30), label = "HP", interactive = False)
85
  speed = gr.Textbox(value = lambda:"25 ft", label = "Speed", interactive = False)
86
+
87
 
88
  with gr.Row():
89
 
 
92
  dcs = gr.Textbox(label = "DC to Smash")
93
  prefs = gr.Textbox(label = "Advantage if:")
94
 
95
+
96
+ # Need to add export feature.
97
+
98
  demo.launch(theme = gr.themes.Monochrome())
requirements.txt CHANGED
@@ -1,3 +1,5 @@
1
  gradio
2
  transformers
3
- torch
 
 
 
1
  gradio
2
  transformers
3
+ torch
4
+ spaces
5
+ accelerate