JohanBeytell commited on
Commit
1f501e4
verified
1 Parent(s): 902ae22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -17
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,12 +79,6 @@ 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
- 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):
@@ -111,13 +105,6 @@ It will generate names for characters, gods, factions, or places.
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)
123
  with gr.Row():
@@ -127,12 +114,11 @@ with gr.Blocks() as demo:
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("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="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()
 
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
  results = []
83
  for _ in range(count):
84
  for attempt in range(retries):
 
105
  - The creators are not responsible for any weirdness it spits out. Use responsibly.
106
  """
107
 
 
 
 
 
 
 
 
108
  with gr.Blocks() as demo:
109
  gr.Markdown(description)
110
  with gr.Row():
 
114
  top_k = gr.Slider(10, 100, step=10, value=40, label="Top-K Sampling")
115
  count = gr.Slider(1, 20, step=1, value=5, label="Names to Generate")
116
  retries = gr.Slider(1, 5, step=1, value=3, label="Max Retries per Name")
117
+ generate_btn = gr.Button("馃幉 Generate Names")
118
  with gr.Column():
119
  output = gr.Dataframe(headers=["Generated Name"], datatype="str", label="Generated Names", interactive=False)
120
+ download = gr.File(label="馃摜 Export Names as .txt")
121
 
122
  generate_btn.click(fn=generate_names, inputs=[prompt, temperature, top_k, count, retries], outputs=[output, download])
 
123
 
124
  demo.launch()