Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,8 +33,7 @@ def parse_generated_text(text: str) -> dict:
|
|
| 33 |
}
|
| 34 |
|
| 35 |
def generate_questions(topic, difficulty, types, count):
|
| 36 |
-
print("Received input:", topic, difficulty, types, count)
|
| 37 |
-
|
| 38 |
try:
|
| 39 |
pipe = pipeline(
|
| 40 |
task="text-generation",
|
|
@@ -48,8 +47,8 @@ def generate_questions(topic, difficulty, types, count):
|
|
| 48 |
|
| 49 |
questions = []
|
| 50 |
|
| 51 |
-
for
|
| 52 |
-
for
|
| 53 |
prompt = (
|
| 54 |
f"Generate a {difficulty} difficulty {q_type} question about {topic}.\n"
|
| 55 |
"Format strictly as follows:\n"
|
|
@@ -66,9 +65,6 @@ def generate_questions(topic, difficulty, types, count):
|
|
| 66 |
generated_text = result[0]['generated_text'].replace(formatted_prompt, "").strip()
|
| 67 |
parsed = parse_generated_text(generated_text)
|
| 68 |
|
| 69 |
-
print("Parsed Output:", parsed)
|
| 70 |
-
|
| 71 |
-
# Safe fallback
|
| 72 |
if not parsed['question']:
|
| 73 |
parsed['question'] = "β οΈ Could not parse question."
|
| 74 |
if not parsed['hint']:
|
|
@@ -78,16 +74,16 @@ def generate_questions(topic, difficulty, types, count):
|
|
| 78 |
questions.append(formatted)
|
| 79 |
|
| 80 |
final_output = "\n\n".join(questions)
|
| 81 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
return final_output
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
print("Error:", e)
|
| 86 |
return f"β Something went wrong: {e}"
|
| 87 |
-
|
| 88 |
-
except Exception as e:
|
| 89 |
-
print("Error:", e)
|
| 90 |
-
return f"Something went wrong: {e}"
|
| 91 |
|
| 92 |
iface = gr.Interface(
|
| 93 |
fn=generate_questions,
|
|
@@ -103,4 +99,4 @@ iface = gr.Interface(
|
|
| 103 |
)
|
| 104 |
|
| 105 |
if __name__ == "__main__":
|
| 106 |
-
iface.queue().launch()
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
def generate_questions(topic, difficulty, types, count):
|
| 36 |
+
print("Received input:", topic, difficulty, types, count)
|
|
|
|
| 37 |
try:
|
| 38 |
pipe = pipeline(
|
| 39 |
task="text-generation",
|
|
|
|
| 47 |
|
| 48 |
questions = []
|
| 49 |
|
| 50 |
+
for q_type in types:
|
| 51 |
+
for _ in range(count):
|
| 52 |
prompt = (
|
| 53 |
f"Generate a {difficulty} difficulty {q_type} question about {topic}.\n"
|
| 54 |
"Format strictly as follows:\n"
|
|
|
|
| 65 |
generated_text = result[0]['generated_text'].replace(formatted_prompt, "").strip()
|
| 66 |
parsed = parse_generated_text(generated_text)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
if not parsed['question']:
|
| 69 |
parsed['question'] = "β οΈ Could not parse question."
|
| 70 |
if not parsed['hint']:
|
|
|
|
| 74 |
questions.append(formatted)
|
| 75 |
|
| 76 |
final_output = "\n\n".join(questions)
|
| 77 |
+
print("Returning this to UI:\n", final_output)
|
| 78 |
+
|
| 79 |
+
if not final_output.strip():
|
| 80 |
+
return "β οΈ No questions were generated."
|
| 81 |
+
|
| 82 |
return final_output
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
print("Error:", e)
|
| 86 |
return f"β Something went wrong: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
iface = gr.Interface(
|
| 89 |
fn=generate_questions,
|
|
|
|
| 99 |
)
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
| 102 |
+
iface.queue().launch()
|