|
import gradio as gr |
|
import torch |
|
from transformers import T5Tokenizer, AutoModelForCausalLM, pipeline |
|
from utils import translate_from_jp_to_en |
|
|
|
tokenizer = T5Tokenizer.from_pretrained("rinna/japanese-gpt-1b") |
|
model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt-1b") |
|
|
|
generator = pipeline("text-generation", tokenizer=tokenizer, model=model) |
|
|
|
def generate(text, max_length=512): |
|
out = generator(text, do_sample=True, max_length=max_length, num_return_sequences=1) |
|
text = out[0]['generated_text'] |
|
|
|
return text, translate_from_jp_to_en(text) |
|
|
|
|
|
title = "JP GPT Demo" |
|
description = "Demo for generating text in Japanase using a GPT model" |
|
article = "Built by Narrativa" |
|
examples = [['日本のeスポーツ障害者がステレオタイプを撃ち落とす', 128]] |
|
gr.Interface(fn=generate, inputs=[gr.inputs.Textbox(lines=4, label="Prompt"), |
|
gr.inputs.Slider(minimum=8, maximum=1024, step=8, default=64, label="Number of tokens")], |
|
outputs=["text", "text"], |
|
title=title, description=description, |
|
article= article, |
|
examples=examples).launch(enable_queue=True) |
|
|