Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# ---------------- app.py ----------------
|
| 2 |
from flask import Flask, request, jsonify
|
| 3 |
import os
|
| 4 |
import uuid
|
|
@@ -79,37 +78,9 @@ def submit_quiz():
|
|
| 79 |
|
| 80 |
return jsonify({'score': correct, 'total': total, 'accuracy': accuracy})
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
if __name__ == '__main__':
|
| 83 |
app.run(host='0.0.0.0', port=7860)
|
| 84 |
-
|
| 85 |
-
# ---------------- model_utils.py ----------------
|
| 86 |
-
from transformers import pipeline
|
| 87 |
-
|
| 88 |
-
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 89 |
-
labels = ["question", "option", "answer", "other"]
|
| 90 |
-
|
| 91 |
-
def classify_chunk(text):
|
| 92 |
-
result = classifier(text, labels)
|
| 93 |
-
return result['labels'][0]
|
| 94 |
-
|
| 95 |
-
def extract_mcqs_with_model(text):
|
| 96 |
-
chunks = [chunk.strip() for chunk in text.split("\n\n") if chunk.strip()]
|
| 97 |
-
mcqs = []
|
| 98 |
-
current = {"question": "", "options": [], "answer": ""}
|
| 99 |
-
|
| 100 |
-
for chunk in chunks:
|
| 101 |
-
label = classify_chunk(chunk)
|
| 102 |
-
if label == "question":
|
| 103 |
-
if current["question"]:
|
| 104 |
-
mcqs.append(current)
|
| 105 |
-
current = {"question": "", "options": [], "answer": ""}
|
| 106 |
-
current["question"] = chunk
|
| 107 |
-
elif label == "option":
|
| 108 |
-
current["options"].append(chunk)
|
| 109 |
-
elif label == "answer":
|
| 110 |
-
current["answer"] = chunk
|
| 111 |
-
|
| 112 |
-
if current["question"]:
|
| 113 |
-
mcqs.append(current)
|
| 114 |
-
return mcqs
|
| 115 |
-
|
|
|
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
import os
|
| 3 |
import uuid
|
|
|
|
| 78 |
|
| 79 |
return jsonify({'score': correct, 'total': total, 'accuracy': accuracy})
|
| 80 |
|
| 81 |
+
@app.route('/')
|
| 82 |
+
def home():
|
| 83 |
+
return "MCQ Extraction Flask API is running!"
|
| 84 |
+
|
| 85 |
if __name__ == '__main__':
|
| 86 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|