File size: 2,572 Bytes
d10214a
539debe
d10214a
 
318834e
d10214a
 
 
 
 
7888e51
d10214a
aff4485
91a8143
d10214a
91a8143
d10214a
ff2a72a
 
2e4a4ab
d10214a
1940b48
d10214a
 
 
91a8143
 
d10214a
 
 
91a8143
d10214a
 
2e4a4ab
 
d10214a
 
301ebcf
aff4485
 
 
e85679c
 
 
 
 
 
 
c219137
 
e85679c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

hf_token= os.getenv("access_token")
tokenizer = AutoTokenizer.from_pretrained("afrizalha/Sasando-1-25M", token=hf_token)
tiny = AutoModelForCausalLM.from_pretrained("afrizalha/Sasando-1-25M", token=hf_token)
tinier = AutoModelForCausalLM.from_pretrained("afrizalha/Sasando-1-7M", token=hf_token)


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."""

def generate(starting_text, choice, temp, top_p):
    if choice == '7M':
        model = tinier
    elif choice == '25M':
        model = tiny
    elif choice == "Info":
        return desc
    
    results = []
    for i in range(5):
        inputs = tokenizer([starting_text], return_tensors="pt").to(model.device)
        outputs = model.generate(
            inputs=inputs.input_ids,
            max_new_tokens=32-len(inputs.input_ids[0]),
            do_sample=True,
            temperature=temp,
            top_p=top_p
        )
        outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
        outputs = outputs[:outputs.find(".")]
        results.append(outputs)
    return "\n\n".join(results)

with gr.Blocks(theme=gr.themes.Soft()) as app:
    starting_text = gr.Textbox(label="Starting text", value="cinta adalah")
    res = gr.Textbox(label="Continuation", value="cinta adalah", scale=2)
    choice = gr.Radio(["7M", "25M", "Info"], label="Select model", info="Built with the Phi-3 architecture", value='Info')
    temp = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7)
    top_p = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, step=0.1, value=0.5)
    gr.Interface(
        fn=generate,
         inputs=[starting_text,choice,temp,top_p],
         outputs=[res],
         allow_flagging="never",
         title="Sasando-1",
         )
    examples=gr.Examples([["gue"], ["presiden"], ["cinta adalah"], ["allah, aku"], ["dia marah karena"],
                       ["inflasi"], ["kolam renang"], ["messi"], ["jalan-jalan"], ["komputer itu"]], [starting_text])
app.launch()