Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
| 4 |
-
import re, unicodedata, random
|
| 5 |
from pathlib import Path
|
|
|
|
| 6 |
|
| 7 |
# === Constants and Config ===
|
| 8 |
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
@@ -72,7 +73,8 @@ def sample_once(prompt, temperature=1.0, top_k=40, max_new=24):
|
|
| 72 |
break
|
| 73 |
seq.append(idx)
|
| 74 |
|
| 75 |
-
|
|
|
|
| 76 |
return clean_name(name)
|
| 77 |
|
| 78 |
# === Gradio UI ===
|
|
@@ -80,8 +82,8 @@ def generate_ui(prompt, temperature, top_k, count):
|
|
| 80 |
results = []
|
| 81 |
for _ in range(count):
|
| 82 |
name = sample_once(prompt, temperature=temperature, top_k=top_k)
|
| 83 |
-
results.append(name)
|
| 84 |
-
return
|
| 85 |
|
| 86 |
description = """🎭 **Fantasy Name Generator**
|
| 87 |
Give it a prompt like `a forgotten warrior king` or `mistress of the black swamp` and it'll generate creative fantasy-style names.
|
|
@@ -96,7 +98,7 @@ with gr.Blocks() as demo:
|
|
| 96 |
top_k = gr.Slider(10, 100, step=10, value=40, label="Top-K")
|
| 97 |
count = gr.Slider(1, 5, step=1, value=3, label="Names to Generate")
|
| 98 |
generate_btn = gr.Button("Generate Names")
|
| 99 |
-
output = gr.
|
| 100 |
generate_btn.click(fn=generate_ui, inputs=[prompt, temperature, top_k, count], outputs=output)
|
| 101 |
|
| 102 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
| 4 |
+
import re, unicodedata, random
|
| 5 |
from pathlib import Path
|
| 6 |
+
import pandas as pd
|
| 7 |
|
| 8 |
# === Constants and Config ===
|
| 9 |
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
|
|
| 73 |
break
|
| 74 |
seq.append(idx)
|
| 75 |
|
| 76 |
+
generated = [itos[i] for i in seq if i not in {BOS, SEP, EOS, PAD}]
|
| 77 |
+
name = ''.join(generated).replace(prompt, "").strip()
|
| 78 |
return clean_name(name)
|
| 79 |
|
| 80 |
# === Gradio UI ===
|
|
|
|
| 82 |
results = []
|
| 83 |
for _ in range(count):
|
| 84 |
name = sample_once(prompt, temperature=temperature, top_k=top_k)
|
| 85 |
+
results.append({"Generated Name": name})
|
| 86 |
+
return pd.DataFrame(results)
|
| 87 |
|
| 88 |
description = """🎭 **Fantasy Name Generator**
|
| 89 |
Give it a prompt like `a forgotten warrior king` or `mistress of the black swamp` and it'll generate creative fantasy-style names.
|
|
|
|
| 98 |
top_k = gr.Slider(10, 100, step=10, value=40, label="Top-K")
|
| 99 |
count = gr.Slider(1, 5, step=1, value=3, label="Names to Generate")
|
| 100 |
generate_btn = gr.Button("Generate Names")
|
| 101 |
+
output = gr.Dataframe(headers=["Generated Name"], datatype="str", label="Generated Fantasy Names", interactive=False)
|
| 102 |
generate_btn.click(fn=generate_ui, inputs=[prompt, temperature, top_k, count], outputs=output)
|
| 103 |
|
| 104 |
demo.launch()
|