File size: 1,186 Bytes
5aeff64
 
4b7a8dd
5aeff64
 
 
 
 
4b7a8dd
5aeff64
cb66b9a
 
4b7a8dd
5aeff64
4b7a8dd
5aeff64
 
 
 
670bf11
5aeff64
 
cb66b9a
5aeff64
 
670bf11
5aeff64
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
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, min_length=512):
    out = generator(text, do_sample=True, min_length=min_length, max_length=1024, 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=128, label="Number of tokens")],
             outputs=["text", "text"],
             title=title, description=description,
             article= article,
             examples=examples).launch(enable_queue=True)