File size: 1,125 Bytes
10bed7b
 
88b191b
 
 
 
 
 
 
 
 
 
 
 
 
10bed7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
import gradio as gr
from transformers import GPT2Tokenizer
import os

os.system(
    "pip3 install thirdai-0.7.18+a1506df-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
)

import importlib
import site

importlib.reload(site)


from thirdai import bolt, licensing

licensing.activate("7511CC-0E24D7-69439D-5D6CBA-33AAFD-V3")

tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = bolt.GenerativeModel.load("./generative.model")


def generate(prompt):
    prompt = tokenizer.encode(prompt)

    stream = model.streaming_generation(
        input_tokens=prompt,
        prediction_chunk_size=2,
        max_predictions=100,
        beam_width=10,
    )

    for res in stream:
        yield tokenizer.decode(res)


with gr.Blocks() as demo:
    output = gr.TextArea(label="Output")
    prompt = gr.Textbox(
        label="Prompt",
    )
    prompt.submit(generate, inputs=[prompt], outputs=[output])

    btn = gr.Button(value="Generate")
    btn.click(generate, inputs=[prompt], outputs=[output])

    gr.ClearButton(components=[prompt, output])

if __name__ == "__main__":
    demo.queue()
    demo.launch()