rf5860 commited on
Commit
f5fa12f
1 Parent(s): 7e1c4ca

Update n_gpu_layers to offload all. Add slider for number of chars

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from llama_cpp import Llama
2
  from huggingface_hub import hf_hub_download
3
  import gradio as gr
 
4
  import random
5
 
6
  repo_id = "TheBloke/Mistral-7B-Instruct-v0.1-GGUF"
@@ -8,7 +9,9 @@ filename = "mistral-7b-instruct-v0.1.Q4_K_M.gguf"
8
  model_file_path = hf_hub_download(repo_id=repo_id, filename=filename)
9
 
10
 
11
- def generate_characters(generate_backstories=False):
 
 
12
  class_list = ["Barbarian", "Bard", "Cleric", "Druid", "Fighter",
13
  "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard"]
14
  sub_class_list = ["Barbarian - Beserker", "Barbarian - Wildheart", "Barbarian - Wild Magic", "Bard - College of Lore", "Bard - College of Valour", "Bard - College of Swords", "Cleric - Life Domain", "Cleric - Light Domain", "Cleric - Trickery Domain", "Cleric - Knowledge Domain", "Cleric - Nature Domain", "Cleric - Tempest Domain", "Cleric - War Domain", "Druid - Circle of the moon", "Druid - Circle of the Land", "Druid - Circle of the Spores", "Fighter - Battle Master", "Fighter - Eldritch Knight", "Fighter - Champion", "Monk - Way of the open hand", "Monk - Way of shadow", "Monk - Way of the four elements",
@@ -42,8 +45,10 @@ def generate_characters(generate_backstories=False):
42
  character['Class'] += f' ({levels_class1} levels), {second_class} ({levels_class2} levels)'
43
  return character
44
 
45
- characters = [generate_character() for _ in range(2)]
46
- characters.append(generate_multiclass_character())
 
 
47
 
48
  def create_character_output(character, generate_backstories=False):
49
  output = ""
@@ -73,7 +78,7 @@ def generate_text_from_prompt(user_prompt,
73
  stop=["<s>", "[/INST]", "Q"]):
74
  mistral_model = Llama(model_path=model_file_path,
75
  n_ctx=4096,
76
- n_gpu_layers=24)
77
 
78
  # Define the parameters
79
  model_output = mistral_model(
@@ -98,8 +103,14 @@ def generate_backstory(character):
98
  if __name__ == "__main__":
99
  iface = gr.Interface(fn=generate_characters,
100
  title="D&D Character Generator",
101
- inputs=[gr.inputs.Checkbox(
102
- label="Generate Backstories?")],
 
 
 
 
 
 
103
  description="Generates 3 random D&D characters.",
104
  outputs="markdown")
105
  iface.launch()
 
1
  from llama_cpp import Llama
2
  from huggingface_hub import hf_hub_download
3
  import gradio as gr
4
+ import gradio.components as grc
5
  import random
6
 
7
  repo_id = "TheBloke/Mistral-7B-Instruct-v0.1-GGUF"
 
9
  model_file_path = hf_hub_download(repo_id=repo_id, filename=filename)
10
 
11
 
12
+ def generate_characters(generate_backstories=False,
13
+ num_characters=1,
14
+ num_multiclass_characters=1):
15
  class_list = ["Barbarian", "Bard", "Cleric", "Druid", "Fighter",
16
  "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard"]
17
  sub_class_list = ["Barbarian - Beserker", "Barbarian - Wildheart", "Barbarian - Wild Magic", "Bard - College of Lore", "Bard - College of Valour", "Bard - College of Swords", "Cleric - Life Domain", "Cleric - Light Domain", "Cleric - Trickery Domain", "Cleric - Knowledge Domain", "Cleric - Nature Domain", "Cleric - Tempest Domain", "Cleric - War Domain", "Druid - Circle of the moon", "Druid - Circle of the Land", "Druid - Circle of the Spores", "Fighter - Battle Master", "Fighter - Eldritch Knight", "Fighter - Champion", "Monk - Way of the open hand", "Monk - Way of shadow", "Monk - Way of the four elements",
 
45
  character['Class'] += f' ({levels_class1} levels), {second_class} ({levels_class2} levels)'
46
  return character
47
 
48
+ characters = [generate_character() for _ in range(num_characters)]
49
+ multiclass_characters = [generate_multiclass_character()
50
+ for _ in range(num_multiclass_characters)]
51
+ characters.extend(multiclass_characters)
52
 
53
  def create_character_output(character, generate_backstories=False):
54
  output = ""
 
78
  stop=["<s>", "[/INST]", "Q"]):
79
  mistral_model = Llama(model_path=model_file_path,
80
  n_ctx=4096,
81
+ n_gpu_layers=-1)
82
 
83
  # Define the parameters
84
  model_output = mistral_model(
 
103
  if __name__ == "__main__":
104
  iface = gr.Interface(fn=generate_characters,
105
  title="D&D Character Generator",
106
+ inputs=[grc.Checkbox(label="Generate Backstories?"),
107
+ grc.Label("Single-class characters?"),
108
+ grc.Slider(minimum=1, maximum=10,
109
+ step=1, default=1),
110
+ grc.Label("Multi-class characters?"),
111
+ grc.Slider(minimum=1, maximum=10,
112
+ step=1, default=1)
113
+ ],
114
  description="Generates 3 random D&D characters.",
115
  outputs="markdown")
116
  iface.launch()