Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,16 +17,20 @@ df = pd.DataFrame(data)
|
|
| 17 |
|
| 18 |
# Função para responder perguntas com GPT-2
|
| 19 |
def answer_question_with_gpt(question):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Supondo que você queira incorporar dados do DataFrame na pergunta
|
| 21 |
prompt = f"Considerando os dados: {df.to_string(index=False)}. Pergunta: {question} Resposta:"
|
| 22 |
inputs = tokenizer(prompt, return_tensors='pt', padding='max_length', truncation=True, max_length=512)
|
| 23 |
attention_mask = inputs['attention_mask']
|
| 24 |
input_ids = inputs['input_ids']
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
generated_ids = model.generate(input_ids, attention_mask=attention_mask, pad_token_id=pad_token_id, max_length=len(input_ids[0]) + 50)
|
| 29 |
|
|
|
|
| 30 |
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 31 |
return generated_text.split("Resposta:")[1] if "Resposta:" in generated_text else generated_text
|
| 32 |
|
|
@@ -57,4 +61,4 @@ with gr.Blocks() as demo:
|
|
| 57 |
ask_button.click(fn=answer_question_with_gpt, inputs=question_input, outputs=answer_output)
|
| 58 |
submit_button.click(fn=add_feedback, inputs=[name_input, feedback_input], outputs=feedback_result)
|
| 59 |
|
| 60 |
-
demo.launch()
|
|
|
|
| 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 |
+
# Gerando texto com o modelo GPT-2
|
| 31 |
+
generated_ids = model.generate(input_ids, attention_mask=attention_mask, max_length=len(input_ids[0]) + 50)
|
|
|
|
| 32 |
|
| 33 |
+
# Decodificando o texto gerado
|
| 34 |
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 35 |
return generated_text.split("Resposta:")[1] if "Resposta:" in generated_text else generated_text
|
| 36 |
|
|
|
|
| 61 |
ask_button.click(fn=answer_question_with_gpt, inputs=question_input, outputs=answer_output)
|
| 62 |
submit_button.click(fn=add_feedback, inputs=[name_input, feedback_input], outputs=feedback_result)
|
| 63 |
|
| 64 |
+
demo.launch()
|