File size: 1,026 Bytes
8a97208
eb443cd
0010001
eb443cd
e5c60ed
47ae43c
eb443cd
94d66a9
 
 
 
 
1127261
8384864
eb443cd
0010001
 
b5f1235
eb443cd
 
8a97208
0010001
8a97208
0010001
 
 
eb443cd
 
8384864
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

# Specify the directory containing the tokenizer's configuration file (config.json)
model_name = "pytorch_model-00001-of-00002.bin"

# Initialize the tokenizer
# tokenizer = AutoTokenizer.from_pretrained(model_name, local_files_only=True)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"


# Initialize the GPT4All model
model = AutoModelForCausalLM.from_pretrained(model_name)

def generate_text(input_text):
    pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
    result = pipe(f"<s>[INST] {input_text} [/INST]")
    return result[0]['generated_text']

text_generation_interface = gr.Interface(
    fn=generate_text,
    inputs=[
        gr.inputs.Textbox(label="Input Text"),
    ],
    outputs=gr.outputs.Textbox(label="Generated Text"),
    title="GPT-4 Text Generation",
).launch()