nicolasmarques commited on
Commit
1258a35
Β·
verified Β·
1 Parent(s): 1ebf7e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
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
- # FunΓ§Γ£o principal da IA
8
- def gerar_resposta(texto, comando):
9
- prompt = f"{comando}: {texto}"
10
- resultado = generator(prompt, max_new_tokens=150, temperature=0.9, do_sample=True)
11
- return resultado[0]["generated_text"].replace(prompt, "").strip()
12
 
13
- # Interface com Gradio
14
- demo = gr.Interface(
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="Texto gerado pela IA"),
21
  title="GPT-2 App Sr. Nicolas",
22
- description="Digite um texto e selecione o que deseja que a IA faΓ§a."
23
  )
24
 
25
- demo.launch()
 
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()