JohanBeytell commited on
Commit
a6bf92b
verified
1 Parent(s): 5066051

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -52,7 +52,7 @@ def clean_name(text, title_case=True, max_repeats=2):
52
  text = unicodedata.normalize("NFC", text)
53
  text = re.sub(r'(.)\1{2,}', lambda m: m.group(1) * max_repeats, text)
54
  text = re.sub(r"鈥橲|\'S", "'s", text)
55
- text = re.sub(r"[^0-9A-Za-z脌-脰脴-枚酶-每'鈥橽-\s]", "", text)
56
  text = re.sub(r"\s+", " ", text).strip()
57
  if title_case:
58
  text = proper_case(text)
@@ -79,6 +79,12 @@ def sample_once(prompt, temperature=1.0, top_k=40, max_new=24):
79
 
80
  # === Generation Function ===
81
  def generate_names(prompt, temperature, top_k, count, retries):
 
 
 
 
 
 
82
  results = []
83
  for _ in range(count):
84
  for attempt in range(retries):
@@ -92,12 +98,25 @@ def generate_names(prompt, temperature, top_k, count, retries):
92
  return df, file_path
93
 
94
  # === UI ===
95
- description = """# 馃 Kaos: A Fantasy Name Generator
96
  Kaos is a small GPT-style transformer trained from scratch using character-level tokenization.
97
  It excels at fantasy and mythic naming conventions.
98
 
99
- 馃挕 Give it a prompt like `'a forgotten warrior king'`, `'priestess of the dusk sea'`, or `'demon of frost'`.
100
- The model will generate fitting fantasy-style names, ready for your characters, worlds, or gods."""
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  with gr.Blocks() as demo:
103
  gr.Markdown(description)
@@ -108,11 +127,12 @@ with gr.Blocks() as demo:
108
  top_k = gr.Slider(10, 100, step=10, value=40, label="Top-K Sampling")
109
  count = gr.Slider(1, 20, step=1, value=5, label="Names to Generate")
110
  retries = gr.Slider(1, 5, step=1, value=3, label="Max Retries per Name")
111
- generate_btn = gr.Button("馃幉 Generate Names")
112
  with gr.Column():
113
  output = gr.Dataframe(headers=["Generated Name"], datatype="str", label="Generated Names", interactive=False)
114
- download = gr.File(label="馃摜 Export Names as .txt")
115
 
116
  generate_btn.click(fn=generate_names, inputs=[prompt, temperature, top_k, count, retries], outputs=[output, download])
 
117
 
118
  demo.launch()
 
52
  text = unicodedata.normalize("NFC", text)
53
  text = re.sub(r'(.)\1{2,}', lambda m: m.group(1) * max_repeats, text)
54
  text = re.sub(r"鈥橲|\'S", "'s", text)
55
+ text = re.sub(r"[^0-9A-Za-z脌-蓮'鈥橽-\s]", "", text)
56
  text = re.sub(r"\s+", " ", text).strip()
57
  if title_case:
58
  text = proper_case(text)
 
79
 
80
  # === Generation Function ===
81
  def generate_names(prompt, temperature, top_k, count, retries):
82
+ prompt = prompt.strip()
83
+ if not prompt:
84
+ raise gr.Error("Prompt cannot be empty.")
85
+ if len(prompt) > 64:
86
+ raise gr.Error("Prompt is too long. Please keep it under 64 characters.")
87
+
88
  results = []
89
  for _ in range(count):
90
  for attempt in range(retries):
 
98
  return df, file_path
99
 
100
  # === UI ===
101
+ description = """# 馃 KaosGen: A Fantasy Name Generator
102
  Kaos is a small GPT-style transformer trained from scratch using character-level tokenization.
103
  It excels at fantasy and mythic naming conventions.
104
 
105
+ Give it a prompt like `'a forgotten warrior king'`, `'priestess of the dusk sea'`, or `'demon of frost'`.
106
+ It will generate names for characters, gods, factions, or places.
107
+
108
+ ### 鈿狅笍 Disclaimers
109
+ - This model may occasionally produce inaccurate, inappropriate, or nonsensical results.
110
+ - It is a fantasy tool and **not intended for general-purpose language tasks**.
111
+ - The creators are not responsible for any weirdness it spits out. Use responsibly.
112
+ """
113
+
114
+ examples = [
115
+ ["a forgotten warrior king"],
116
+ ["queen of the shattered realm"],
117
+ ["blacksmith of shadows"],
118
+ ["titan of the blazing sky"]
119
+ ]
120
 
121
  with gr.Blocks() as demo:
122
  gr.Markdown(description)
 
127
  top_k = gr.Slider(10, 100, step=10, value=40, label="Top-K Sampling")
128
  count = gr.Slider(1, 20, step=1, value=5, label="Names to Generate")
129
  retries = gr.Slider(1, 5, step=1, value=3, label="Max Retries per Name")
130
+ generate_btn = gr.Button("\ud83c\udfb2 Generate Names")
131
  with gr.Column():
132
  output = gr.Dataframe(headers=["Generated Name"], datatype="str", label="Generated Names", interactive=False)
133
+ download = gr.File(label="\ud83d\udcc5 Export Names as .txt")
134
 
135
  generate_btn.click(fn=generate_names, inputs=[prompt, temperature, top_k, count, retries], outputs=[output, download])
136
+ gr.Examples(examples=examples, inputs=prompt)
137
 
138
  demo.launch()