Spaces:
Runtime error
Runtime error
Commit
·
eb443cd
1
Parent(s):
47ae43c
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from transformers import (
|
4 |
-
AutoModelForCausalLM,
|
5 |
-
AutoTokenizer,
|
6 |
-
BitsAndBytesConfig,
|
7 |
-
HfArgumentParser,
|
8 |
-
TrainingArguments,
|
9 |
-
pipeline,
|
10 |
-
logging,
|
11 |
-
)
|
12 |
|
13 |
-
# Specify the
|
14 |
-
model_name = "
|
15 |
-
|
16 |
-
# tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
17 |
-
# tokenizer.pad_token = tokenizer.eos_token
|
18 |
-
# tokenizer.padding_side = "right" # Fix weird overflow issue with fp16 training
|
19 |
|
|
|
20 |
tokenizer = AutoTokenizer.from_pretrained(model_name, local_files_only=True)
|
21 |
|
22 |
-
|
23 |
# Initialize the GPT4All model
|
24 |
-
|
25 |
-
model = AutoModelForCausalLM.from_pretrained(
|
26 |
-
model_name,
|
27 |
-
quantization_config=bnb_config,
|
28 |
-
device_map=device_map
|
29 |
-
)
|
30 |
|
31 |
def generate_text(input_text):
|
32 |
-
# output = model.generate(input_text)
|
33 |
-
# return output
|
34 |
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
|
35 |
-
result = pipe(f"<s>[INST] {
|
36 |
-
return result
|
37 |
|
38 |
text_generation_interface = gr.Interface(
|
39 |
fn=generate_text,
|
40 |
inputs=[
|
41 |
gr.inputs.Textbox(label="Input Text"),
|
42 |
],
|
43 |
-
outputs=gr.
|
44 |
-
title="
|
45 |
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Specify the directory containing the tokenizer's configuration file (config.json)
|
5 |
+
model_name = "path/to/tokenizer_directory"
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Initialize the tokenizer
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name, local_files_only=True)
|
9 |
|
|
|
10 |
# Initialize the GPT4All model
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def generate_text(input_text):
|
|
|
|
|
14 |
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
|
15 |
+
result = pipe(f"<s>[INST] {input_text} [/INST]")
|
16 |
+
return result[0]['generated_text']
|
17 |
|
18 |
text_generation_interface = gr.Interface(
|
19 |
fn=generate_text,
|
20 |
inputs=[
|
21 |
gr.inputs.Textbox(label="Input Text"),
|
22 |
],
|
23 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
24 |
+
title="GPT-4 Text Generation",
|
25 |
).launch()
|