Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,20 +17,23 @@ df = pd.DataFrame(data)
|
|
| 17 |
|
| 18 |
# Função para responder perguntas com GPT-2
|
| 19 |
def answer_question_with_gpt(question):
|
| 20 |
-
# Certifique-se de que o pad_token está definido como eos_token
|
| 21 |
if tokenizer.pad_token is None:
|
| 22 |
tokenizer.pad_token = tokenizer.eos_token
|
| 23 |
|
| 24 |
-
# Supondo que você queira incorporar dados do DataFrame na pergunta
|
| 25 |
prompt = f"Considerando os dados: {df.to_string(index=False)}. Pergunta: {question} Resposta:"
|
| 26 |
inputs = tokenizer(prompt, return_tensors='pt', padding='max_length', truncation=True, max_length=512)
|
| 27 |
attention_mask = inputs['attention_mask']
|
| 28 |
input_ids = inputs['input_ids']
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
# Decodificando o texto gerado
|
| 34 |
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 35 |
return generated_text
|
| 36 |
|
|
@@ -45,13 +48,11 @@ def add_feedback(nome, feedback):
|
|
| 45 |
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
gr.Markdown("# Sistema de Consulta e Feedback de Dados")
|
| 48 |
-
|
| 49 |
with gr.Row():
|
| 50 |
with gr.Column():
|
| 51 |
question_input = gr.Textbox(label="Faça uma Pergunta")
|
| 52 |
answer_output = gr.Textbox(label="Resposta", interactive=False)
|
| 53 |
ask_button = gr.Button("Perguntar")
|
| 54 |
-
|
| 55 |
with gr.Column():
|
| 56 |
name_input = gr.Textbox(label="Nome para Feedback")
|
| 57 |
feedback_input = gr.Textbox(label="Feedback")
|
|
|
|
| 17 |
|
| 18 |
# Função para responder perguntas com GPT-2
|
| 19 |
def answer_question_with_gpt(question):
|
|
|
|
| 20 |
if tokenizer.pad_token is None:
|
| 21 |
tokenizer.pad_token = tokenizer.eos_token
|
| 22 |
|
|
|
|
| 23 |
prompt = f"Considerando os dados: {df.to_string(index=False)}. Pergunta: {question} Resposta:"
|
| 24 |
inputs = tokenizer(prompt, return_tensors='pt', padding='max_length', truncation=True, max_length=512)
|
| 25 |
attention_mask = inputs['attention_mask']
|
| 26 |
input_ids = inputs['input_ids']
|
| 27 |
|
| 28 |
+
generated_ids = model.generate(
|
| 29 |
+
input_ids,
|
| 30 |
+
attention_mask=attention_mask,
|
| 31 |
+
max_length=len(input_ids[0]) + 100, # Aumentar o limite de geração
|
| 32 |
+
temperature=0.7, # Ajustar a criatividade
|
| 33 |
+
top_p=0.9, # Usar nucleus sampling
|
| 34 |
+
no_repeat_ngram_size=2 # Evitar repetições desnecessárias
|
| 35 |
+
)
|
| 36 |
|
|
|
|
| 37 |
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 38 |
return generated_text
|
| 39 |
|
|
|
|
| 48 |
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
gr.Markdown("# Sistema de Consulta e Feedback de Dados")
|
|
|
|
| 51 |
with gr.Row():
|
| 52 |
with gr.Column():
|
| 53 |
question_input = gr.Textbox(label="Faça uma Pergunta")
|
| 54 |
answer_output = gr.Textbox(label="Resposta", interactive=False)
|
| 55 |
ask_button = gr.Button("Perguntar")
|
|
|
|
| 56 |
with gr.Column():
|
| 57 |
name_input = gr.Textbox(label="Nome para Feedback")
|
| 58 |
feedback_input = gr.Textbox(label="Feedback")
|