Update app.py
Browse files
app.py
CHANGED
|
@@ -10,21 +10,22 @@ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
| 10 |
|
| 11 |
def generate_questions(email):
|
| 12 |
"""Generates questions based on the input email."""
|
| 13 |
-
# Encode the email with tokenizer
|
| 14 |
-
inputs = tokenizer(email, return_tensors="pt")
|
|
|
|
| 15 |
|
| 16 |
-
# Generate questions using model
|
| 17 |
generation = model.generate(
|
| 18 |
-
|
| 19 |
max_length=256, # Adjust max length as needed
|
| 20 |
num_beams=5, # Adjust beam search for better quality (slower)
|
| 21 |
early_stopping=True,
|
| 22 |
-
prompt="What are the important questions or things that need to be addressed in this email:\n",
|
| 23 |
)
|
| 24 |
|
| 25 |
# Decode the generated text
|
| 26 |
return tokenizer.decode(generation[0], skip_special_tokens=True)
|
| 27 |
|
|
|
|
| 28 |
def generate_answers(questions):
|
| 29 |
"""Generates possible answers to the input questions."""
|
| 30 |
# Encode each question with tokenizer, separated by newline
|
|
|
|
| 10 |
|
| 11 |
def generate_questions(email):
|
| 12 |
"""Generates questions based on the input email."""
|
| 13 |
+
# Encode the email and prompt together with tokenizer
|
| 14 |
+
inputs = tokenizer(email, return_tensors="pt", add_special_tokens=True)
|
| 15 |
+
inputs["input_ids"] = [tokenizer.cls_token_id] + inputs["input_ids"] # Add CLS token at the beginning
|
| 16 |
|
| 17 |
+
# Generate questions using model
|
| 18 |
generation = model.generate(
|
| 19 |
+
**inputs, # Unpack the entire inputs dictionary
|
| 20 |
max_length=256, # Adjust max length as needed
|
| 21 |
num_beams=5, # Adjust beam search for better quality (slower)
|
| 22 |
early_stopping=True,
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
# Decode the generated text
|
| 26 |
return tokenizer.decode(generation[0], skip_special_tokens=True)
|
| 27 |
|
| 28 |
+
|
| 29 |
def generate_answers(questions):
|
| 30 |
"""Generates possible answers to the input questions."""
|
| 31 |
# Encode each question with tokenizer, separated by newline
|