Spaces:
Runtime error
Runtime error
Prajjwal888
commited on
Commit
Β·
33e502d
1
Parent(s):
f552345
update app.py
Browse files
app.py
CHANGED
|
@@ -40,7 +40,6 @@ def generate_questions(topic, difficulty, types, count):
|
|
| 40 |
task="text-generation",
|
| 41 |
model=model,
|
| 42 |
tokenizer=tokenizer,
|
| 43 |
-
# device=0,
|
| 44 |
max_length=200,
|
| 45 |
temperature=0.7,
|
| 46 |
top_p=0.9,
|
|
@@ -67,10 +66,25 @@ def generate_questions(topic, difficulty, types, count):
|
|
| 67 |
generated_text = result[0]['generated_text'].replace(formatted_prompt, "").strip()
|
| 68 |
parsed = parse_generated_text(generated_text)
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
except Exception as e:
|
| 75 |
print("Error:", e)
|
| 76 |
return f"Something went wrong: {e}"
|
|
@@ -88,5 +102,5 @@ iface = gr.Interface(
|
|
| 88 |
description="Enter a topic, select difficulty and question types to generate AI-powered questions."
|
| 89 |
)
|
| 90 |
|
| 91 |
-
|
| 92 |
-
iface.launch()
|
|
|
|
| 40 |
task="text-generation",
|
| 41 |
model=model,
|
| 42 |
tokenizer=tokenizer,
|
|
|
|
| 43 |
max_length=200,
|
| 44 |
temperature=0.7,
|
| 45 |
top_p=0.9,
|
|
|
|
| 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']:
|
| 75 |
+
parsed['hint'] = "No hint available"
|
| 76 |
|
| 77 |
+
formatted = f"**Type**: {q_type}\n\n**Question**: {parsed['question']}\n\n**Hint**: {parsed['hint']}\n\n---"
|
| 78 |
+
questions.append(formatted)
|
| 79 |
+
|
| 80 |
+
final_output = "\n\n".join(questions)
|
| 81 |
+
print("Final Output:", final_output)
|
| 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}"
|
|
|
|
| 102 |
description="Enter a topic, select difficulty and question types to generate AI-powered questions."
|
| 103 |
)
|
| 104 |
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
iface.queue().launch()
|