Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("PlanTL-GOB-ES/gpt2-base-bne")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("PlanTL-GOB-ES/gpt2-base-bne")
|
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, max_length=100)
|
12 |
+
generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
13 |
+
return generated_text
|
14 |
+
|
15 |
+
title = "Demo Generador de Texto Español GPT2"
|
16 |
+
description = "Aplicación para generar texto por ecarbo"
|
17 |
+
|
18 |
+
gr.Interface(
|
19 |
+
text_generation,
|
20 |
+
[gr.inputs.Textbox(lines=2, label="Ingrese el texto"), gr.inputs.Number(default=10, label="Ingrese numero semilla")],
|
21 |
+
[gr.outputs.Textbox(type="auto", label="Texto Generado")],
|
22 |
+
title=title,
|
23 |
+
description=description,
|
24 |
+
theme="huggingface"
|
25 |
+
).launch()
|