Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
import gradio as gr
|
4 |
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained('TrLOX/gpt2-tdk')
|
6 |
+
model = AutoModelForCausalLM.from_pretrained('TrLOX/gpt2-tdk')
|
7 |
|
8 |
+
def text_generation(input_text, seed):
|
9 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
10 |
+
torch.manual_seed(seed) # Max value: 18446744073709551615
|
11 |
+
outputs = model.generate(input_ids, do_sample=True, min_length=50, max_length=200)
|
12 |
+
generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
13 |
+
return generated_text
|
14 |
+
|
15 |
+
title = "TDK GPT2"
|
16 |
+
description = "Title and description generation by keywords"
|
17 |
+
|
18 |
+
gr.Interface(
|
19 |
+
text_generation,
|
20 |
+
[gr.inputs.Textbox(lines=2, label="Enter input text"), gr.inputs.Number(default=10, label="Enter seed number")],
|
21 |
+
[gr.outputs.Textbox(type="auto", label="Text Generated")],
|
22 |
+
title=title,
|
23 |
+
description=description,
|
24 |
+
theme="huggingface"
|
25 |
+
).launch()
|