Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,6 @@ import torch
|
|
3 |
from transformers import pipeline, AutoTokenizer
|
4 |
import gradio as gr
|
5 |
|
6 |
-
@GPU(duration=120)
|
7 |
-
|
8 |
# 日本語モデルを指定
|
9 |
model_name = "rinna/japanese-gpt2-medium"
|
10 |
|
@@ -13,6 +11,8 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
13 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
14 |
generator = pipeline('text-generation', model=model_name, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
|
15 |
|
|
|
|
|
16 |
def generate_text(prompt, max_length):
|
17 |
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
18 |
return result[0]['generated_text']
|
|
|
3 |
from transformers import pipeline, AutoTokenizer
|
4 |
import gradio as gr
|
5 |
|
|
|
|
|
6 |
# 日本語モデルを指定
|
7 |
model_name = "rinna/japanese-gpt2-medium"
|
8 |
|
|
|
11 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
12 |
generator = pipeline('text-generation', model=model_name, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
|
13 |
|
14 |
+
@GPU(duration=120)
|
15 |
+
|
16 |
def generate_text(prompt, max_length):
|
17 |
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
18 |
return result[0]['generated_text']
|