File size: 1,343 Bytes
e20e7d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

model_name = "Azurro/APT-1B-Base"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

generator = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    device_map="auto",
)

def generate_text(prompt, max_length, temperature, top_k, top_p, beams):
    output = generator(prompt, 
                       max_length=max_length, 
                       temperature=temperature, 
                       top_k=top_k,
                       do_sample=True,
                       top_p=top_p,
                       num_beams=beams)
    return output[0]['generated_text']

input_text = gr.inputs.Textbox(label="Input Text")
max_length = gr.inputs.Slider(1, 200, step=1, default=100, label="Max Length")
temperature = gr.inputs.Slider(0.1, 1.0, step=0.1, default=0.8, label="Temperature")
top_k = gr.inputs.Slider(1, 200, step=1, default=10, label="Top K")
top_p = gr.inputs.Slider(0.1, 2.0, step=0.1, default=0.95, label="Top P")
beams = gr.inputs.Slider(1, 20, step=1, default=1, label="Beams")

outputs = gr.outputs.Textbox(label="Generated Text")

gr.Interface(generate_text, inputs=[input_text, max_length, temperature, top_k, top_p, beams], outputs=outputs).launch()