|
import gradio as gr |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
model_path = "./" |
|
model_name = "pytorch_model-00001-of-00002.bin" |
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained(model_path) |
|
tokenizer = AutoTokenizer.from_pretrained(model_path) |
|
|
|
|
|
def generate_text(input_text): |
|
input_ids = tokenizer(input_text, return_tensors="pt").input_ids |
|
output = model.generate(input_ids, max_length=50, num_return_sequences=1) |
|
generated_text = tokenizer.decode(output[0], skip_special_tokens=True) |
|
return 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", |
|
) |
|
|
|
|
|
text_generation_interface.launch() |
|
|