afrizalha commited on
Commit
d10214a
·
verified ·
1 Parent(s): 1cfa43e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ hf_token= os.getenv("access_token")
4
+
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("afrizalha/Sasando-1-25M", token=hf_token)
8
+ tiny = AutoModelForCausalLM.from_pretrained("afrizalha/Sasando-1-25M", token=hf_token)
9
+ tinier = AutoModelForCausalLM.from_pretrained("afrizalha/Sasando-1-7M", token=hf_token)
10
+
11
+
12
+ 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."""
13
+
14
+ def generate(starting_text, choice, num_runs,temp,top_p):
15
+ if choice == '7M':
16
+ model = tinier
17
+ elif choice == '25M':
18
+ model = tiny
19
+ elif choice == 'Info':
20
+ return desc
21
+
22
+ results = []
23
+ for i in range(num_runs):
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),
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"], label="Model size", info="Built with the Phi-3 architecture")
40
+ num_runs = gr.Slider(label="Number of examples", minimum=1, maximum=10, step=1, value=5)
41
+ temp = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7)
42
+ top_p = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, step=0.1, value=0.5)
43
+ res = gr.Textbox(label="Continuation")
44
+ gr.Interface(
45
+ fn=generate,
46
+ inputs=[starting_text,choice,num_runs,temp,top_p],
47
+ outputs=[res],
48
+ allow_flagging="never",
49
+ title="Sasando-1",
50
+ )
51
+ examples=gr.Examples([["gue"], ["presiden"], ["cinta adalah"], ["allah, aku"]], [starting_text])
52
+
53
+ app.launch(share=True)