Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,22 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
-
# Cria pipeline de geraΓ§Γ£o de texto com GPT-2
|
5 |
generator = pipeline("text-generation", model="gpt2")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
prompt =
|
10 |
-
|
11 |
-
return resultado[0]["generated_text"].replace(prompt, "").strip()
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
fn=gerar_resposta,
|
16 |
inputs=[
|
17 |
gr.Textbox(lines=5, label="Texto de entrada"),
|
18 |
gr.Dropdown(choices=["Expandir", "Resumir", "Simplificar", "Continuar"], label="Comando")
|
19 |
],
|
20 |
-
outputs=gr.Textbox(label="
|
21 |
title="GPT-2 App Sr. Nicolas",
|
22 |
-
description="Digite um texto e selecione o
|
23 |
)
|
24 |
|
25 |
-
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
|
|
4 |
generator = pipeline("text-generation", model="gpt2")
|
5 |
|
6 |
+
def generate_response(text, command):
|
7 |
+
prompt = f"{command}: {text}"
|
8 |
+
result = generator(prompt, max_new_tokens=150, temperature=0.9, do_sample=True)
|
9 |
+
return result[0]["generated_text"].replace(prompt, "").strip()
|
|
|
10 |
|
11 |
+
interface = gr.Interface(
|
12 |
+
fn=generate_response,
|
|
|
13 |
inputs=[
|
14 |
gr.Textbox(lines=5, label="Texto de entrada"),
|
15 |
gr.Dropdown(choices=["Expandir", "Resumir", "Simplificar", "Continuar"], label="Comando")
|
16 |
],
|
17 |
+
outputs=gr.Textbox(label="Resposta gerada"),
|
18 |
title="GPT-2 App Sr. Nicolas",
|
19 |
+
description="Digite um texto e selecione o comando desejado."
|
20 |
)
|
21 |
|
22 |
+
interface.launch()
|