Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,12 +21,18 @@ def generate_mcqs(text, num_questions=5):
|
|
| 21 |
model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-large")
|
| 22 |
|
| 23 |
# Tokenize the input text
|
| 24 |
-
inputs = tokenizer(text, return_tensors="pt", max_length=
|
| 25 |
|
| 26 |
mcqs = []
|
| 27 |
for _ in range(num_questions):
|
| 28 |
# Generate a single MCQ at a time
|
| 29 |
-
output = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Decode the generated sequence
|
| 32 |
mcq = tokenizer.decode(output[0], skip_special_tokens=True)
|
|
|
|
| 21 |
model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-large")
|
| 22 |
|
| 23 |
# Tokenize the input text
|
| 24 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True)
|
| 25 |
|
| 26 |
mcqs = []
|
| 27 |
for _ in range(num_questions):
|
| 28 |
# Generate a single MCQ at a time
|
| 29 |
+
output = model.generate(
|
| 30 |
+
**inputs,
|
| 31 |
+
max_length=512, # Adjusted to match the tokenized input length
|
| 32 |
+
max_new_tokens=100, # Limit the number of new tokens added during generation
|
| 33 |
+
temperature=0.7,
|
| 34 |
+
num_return_sequences=1
|
| 35 |
+
)
|
| 36 |
|
| 37 |
# Decode the generated sequence
|
| 38 |
mcq = tokenizer.decode(output[0], skip_special_tokens=True)
|