Update app.py
Browse files
app.py
CHANGED
@@ -10,29 +10,30 @@ tinier = AutoModelForCausalLM.from_pretrained("afrizalha/Sasando-1-7M", token=hf
|
|
10 |
|
11 |
desc = """Sasando-1 is a tiny, highly experimental text generator built using the Phi-3 architecture. It comes with two variations of microscopic sizes: 7M and 25M parameters. It is trained on a tightly-controlled Indo4B dataset filtered to only have 18000 unique words. The method is inspired by Microsoft's TinyStories paper which demonstrates that a tiny language model can produce fluent text when trained on tightly-controlled dataset.\n\nTry prompting with two simple words, and let the model continue. Fun examples provided below."""
|
12 |
|
13 |
-
def generate(starting_text, choice,
|
14 |
-
if choice == '7M':
|
15 |
model = tinier
|
16 |
-
elif choice == '25M':
|
17 |
model = tiny
|
18 |
elif choice == 'Info':
|
19 |
-
|
20 |
-
|
|
|
21 |
results = []
|
22 |
for i in range(5):
|
23 |
inputs = tokenizer([starting_text], return_tensors="pt").to(model.device)
|
24 |
outputs = model.generate(
|
25 |
inputs=inputs.input_ids,
|
26 |
-
max_new_tokens=32-len(inputs.input_ids),
|
27 |
-
do_sample=True,
|
28 |
temperature=temp,
|
29 |
top_p=top_p
|
30 |
)
|
31 |
-
outputs = tokenizer.batch_decode(outputs,skip_special_tokens=True)[0]
|
32 |
outputs = outputs[:outputs.find(".")]
|
33 |
results.append(outputs)
|
34 |
-
|
35 |
-
|
36 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
37 |
starting_text = gr.Textbox(label="Starting text", value="cinta adalah")
|
38 |
choice = gr.Radio(["7M", "25M", "Info"], label="Select model", info="Built with the Phi-3 architecture")
|
|
|
10 |
|
11 |
desc = """Sasando-1 is a tiny, highly experimental text generator built using the Phi-3 architecture. It comes with two variations of microscopic sizes: 7M and 25M parameters. It is trained on a tightly-controlled Indo4B dataset filtered to only have 18000 unique words. The method is inspired by Microsoft's TinyStories paper which demonstrates that a tiny language model can produce fluent text when trained on tightly-controlled dataset.\n\nTry prompting with two simple words, and let the model continue. Fun examples provided below."""
|
12 |
|
13 |
+
def generate(starting_text, choice, temp, top_p):
|
14 |
+
if choice == '7M':
|
15 |
model = tinier
|
16 |
+
elif choice == '25M':
|
17 |
model = tiny
|
18 |
elif choice == 'Info':
|
19 |
+
yield desc
|
20 |
+
return
|
21 |
+
|
22 |
results = []
|
23 |
for i in range(5):
|
24 |
inputs = tokenizer([starting_text], return_tensors="pt").to(model.device)
|
25 |
outputs = model.generate(
|
26 |
inputs=inputs.input_ids,
|
27 |
+
max_new_tokens=32-len(inputs.input_ids[0]),
|
28 |
+
do_sample=True,
|
29 |
temperature=temp,
|
30 |
top_p=top_p
|
31 |
)
|
32 |
+
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
33 |
outputs = outputs[:outputs.find(".")]
|
34 |
results.append(outputs)
|
35 |
+
yield "\n\n".join(results)
|
36 |
+
|
37 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
38 |
starting_text = gr.Textbox(label="Starting text", value="cinta adalah")
|
39 |
choice = gr.Radio(["7M", "25M", "Info"], label="Select model", info="Built with the Phi-3 architecture")
|