Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,9 +38,9 @@ def generate_quiz(standard, topic, quiz_type, difficulty, num_questions):
|
|
38 |
{
|
39 |
"questions": [
|
40 |
{
|
41 |
-
"question": "What is the
|
42 |
-
"options": ["A)
|
43 |
-
"answer": "C)
|
44 |
}
|
45 |
]
|
46 |
}
|
@@ -49,8 +49,8 @@ def generate_quiz(standard, topic, quiz_type, difficulty, num_questions):
|
|
49 |
{
|
50 |
"questions": [
|
51 |
{
|
52 |
-
"question": "The Sun is a
|
53 |
-
"answer": "
|
54 |
}
|
55 |
]
|
56 |
}
|
@@ -59,8 +59,8 @@ def generate_quiz(standard, topic, quiz_type, difficulty, num_questions):
|
|
59 |
{
|
60 |
"questions": [
|
61 |
{
|
62 |
-
"question": "The
|
63 |
-
"answer": "
|
64 |
}
|
65 |
]
|
66 |
}
|
@@ -68,16 +68,20 @@ def generate_quiz(standard, topic, quiz_type, difficulty, num_questions):
|
|
68 |
}
|
69 |
|
70 |
prompt = f"""
|
71 |
-
Generate {
|
72 |
|
73 |
-
|
74 |
|
75 |
-
|
76 |
{format_example[quiz_type]}
|
77 |
"""
|
78 |
|
79 |
try:
|
80 |
response = model.predict(prompt).strip()
|
|
|
|
|
|
|
|
|
81 |
quiz_data = json.loads(response)
|
82 |
return quiz_data if "questions" in quiz_data else None
|
83 |
except json.JSONDecodeError:
|
@@ -165,3 +169,4 @@ if st.button("✅ Submit Quiz"):
|
|
165 |
st.error("⚠️ Quiz data not available. Please regenerate the quiz.")
|
166 |
|
167 |
|
|
|
|
38 |
{
|
39 |
"questions": [
|
40 |
{
|
41 |
+
"question": "What is the capital of France?",
|
42 |
+
"options": ["A) Berlin", "B) Madrid", "C) Paris", "D) Rome"],
|
43 |
+
"answer": "C) Paris"
|
44 |
}
|
45 |
]
|
46 |
}
|
|
|
49 |
{
|
50 |
"questions": [
|
51 |
{
|
52 |
+
"question": "The Sun is a star.",
|
53 |
+
"answer": "True"
|
54 |
}
|
55 |
]
|
56 |
}
|
|
|
59 |
{
|
60 |
"questions": [
|
61 |
{
|
62 |
+
"question": "The powerhouse of the cell is the ____.",
|
63 |
+
"answer": "Mitochondria"
|
64 |
}
|
65 |
]
|
66 |
}
|
|
|
68 |
}
|
69 |
|
70 |
prompt = f"""
|
71 |
+
You are a quiz generator bot. Generate a {quiz_type} quiz with {num_questions} questions for a {standard} grade student on the topic '{topic}' with {difficulty} difficulty.
|
72 |
|
73 |
+
Strictly return the response in JSON format.
|
74 |
|
75 |
+
Format Example:
|
76 |
{format_example[quiz_type]}
|
77 |
"""
|
78 |
|
79 |
try:
|
80 |
response = model.predict(prompt).strip()
|
81 |
+
json_start = response.find('{')
|
82 |
+
json_end = response.rfind('}')
|
83 |
+
if json_start != -1 and json_end != -1:
|
84 |
+
response = response[json_start:json_end+1] # Extract valid JSON
|
85 |
quiz_data = json.loads(response)
|
86 |
return quiz_data if "questions" in quiz_data else None
|
87 |
except json.JSONDecodeError:
|
|
|
169 |
st.error("⚠️ Quiz data not available. Please regenerate the quiz.")
|
170 |
|
171 |
|
172 |
+
|