File size: 1,003 Bytes
7d914dc
 
 
 
 
 
 
 
 
1c340be
7d914dc
1c340be
7d914dc
 
 
 
5b89022
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import gradio as gr

tokenizer = AutoTokenizer.from_pretrained('Aityz/Aityz-3B')
model = AutoModelForCausalLM.from_pretrained('Aityz/Aityz-3B')

def generate(instruction, input = None, maxtokens: int = 20):
    if input is not None:
        ln = f'Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: {instruction} ### Input: {input} \n### Response:'
    if input is None:
        ln = f'Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: {instruction} ### Response:'
    inputs = tokenizer(ln, return_tensors="pt")
    output = model.generate(inputs=inputs['input_ids'], max_new_tokens=maxtokens)
    return tokenizer.decode(output[0].tolist())

inter = gr.Interface(fn=generate, inputs=["textbox", "textbox", gr.Slider(1, 1000, value=100)], outputs="textbox")
inter.launch(share=False)