Spaces:
Sleeping
Sleeping
update 2 difficulty endpoint and 2 original endpoint
Browse files- app.py +5 -5
- generator.py +7 -7
app.py
CHANGED
|
@@ -125,7 +125,7 @@ async def upload_multiple_files(
|
|
| 125 |
@app.post("/generate_saved", response_model=GenerateResponse)
|
| 126 |
async def generate_saved_endpoint(
|
| 127 |
n_easy_questions: int = Form(3),
|
| 128 |
-
n_medium_questions: int = Form(5),
|
| 129 |
n_hard_questions: int = Form(2),
|
| 130 |
qdrant_filename: str = Form("default_filename"),
|
| 131 |
collection_name: str = Form("programming"),
|
|
@@ -139,13 +139,13 @@ async def generate_saved_endpoint(
|
|
| 139 |
global rag
|
| 140 |
if rag is None:
|
| 141 |
raise HTTPException(status_code=503, detail="RAGMCQ not ready on server.")
|
| 142 |
-
|
| 143 |
difficulty_counts = {
|
| 144 |
"easy": n_easy_questions,
|
| 145 |
"medium": n_medium_questions,
|
| 146 |
"hard": n_hard_questions
|
| 147 |
}
|
| 148 |
-
|
| 149 |
all_mcqs = {}
|
| 150 |
counter = 1
|
| 151 |
|
|
@@ -205,7 +205,7 @@ async def generate_endpoint(
|
|
| 205 |
background_tasks: BackgroundTasks,
|
| 206 |
file: UploadFile = File(...),
|
| 207 |
n_easy_questions: int = Form(3),
|
| 208 |
-
n_medium_questions: int = Form(5),
|
| 209 |
n_hard_questions: int = Form(2),
|
| 210 |
qdrant_filename: str = Form("default_filename"),
|
| 211 |
collection_name: str = Form("programming"),
|
|
@@ -247,7 +247,7 @@ async def generate_endpoint(
|
|
| 247 |
"medium": n_medium_questions,
|
| 248 |
"hard": n_hard_questions
|
| 249 |
}
|
| 250 |
-
|
| 251 |
all_mcqs = {}
|
| 252 |
counter = 1
|
| 253 |
|
|
|
|
| 125 |
@app.post("/generate_saved", response_model=GenerateResponse)
|
| 126 |
async def generate_saved_endpoint(
|
| 127 |
n_easy_questions: int = Form(3),
|
| 128 |
+
n_medium_questions: int = Form(5),
|
| 129 |
n_hard_questions: int = Form(2),
|
| 130 |
qdrant_filename: str = Form("default_filename"),
|
| 131 |
collection_name: str = Form("programming"),
|
|
|
|
| 139 |
global rag
|
| 140 |
if rag is None:
|
| 141 |
raise HTTPException(status_code=503, detail="RAGMCQ not ready on server.")
|
| 142 |
+
|
| 143 |
difficulty_counts = {
|
| 144 |
"easy": n_easy_questions,
|
| 145 |
"medium": n_medium_questions,
|
| 146 |
"hard": n_hard_questions
|
| 147 |
}
|
| 148 |
+
|
| 149 |
all_mcqs = {}
|
| 150 |
counter = 1
|
| 151 |
|
|
|
|
| 205 |
background_tasks: BackgroundTasks,
|
| 206 |
file: UploadFile = File(...),
|
| 207 |
n_easy_questions: int = Form(3),
|
| 208 |
+
n_medium_questions: int = Form(5),
|
| 209 |
n_hard_questions: int = Form(2),
|
| 210 |
qdrant_filename: str = Form("default_filename"),
|
| 211 |
collection_name: str = Form("programming"),
|
|
|
|
| 247 |
"medium": n_medium_questions,
|
| 248 |
"hard": n_hard_questions
|
| 249 |
}
|
| 250 |
+
|
| 251 |
all_mcqs = {}
|
| 252 |
counter = 1
|
| 253 |
|
generator.py
CHANGED
|
@@ -604,7 +604,7 @@ class RAGMCQ:
|
|
| 604 |
}
|
| 605 |
|
| 606 |
return report
|
| 607 |
-
|
| 608 |
def connect_qdrant(self, url: str, api_key: str = None, prefer_grpc: bool = False):
|
| 609 |
if not _HAS_QDRANT:
|
| 610 |
raise RuntimeError("qdrant-client is not installed. Install with `pip install qdrant-client`.")
|
|
@@ -896,7 +896,7 @@ class RAGMCQ:
|
|
| 896 |
|
| 897 |
if "error" in list(mcq_block.keys()):
|
| 898 |
return output
|
| 899 |
-
|
| 900 |
for item in sorted(mcq_block.keys(), key=lambda x: int(x)):
|
| 901 |
qcount += 1
|
| 902 |
output[str(qcount)] = mcq_block[item]
|
|
@@ -996,7 +996,7 @@ class RAGMCQ:
|
|
| 996 |
res = self._retrieve(stmt, top_k=1)
|
| 997 |
except Exception:
|
| 998 |
res = []
|
| 999 |
-
|
| 1000 |
if res:
|
| 1001 |
raw_score = float(res[0][1])
|
| 1002 |
emb_support = safe_map_sim(raw_score)
|
|
@@ -1194,9 +1194,9 @@ class RAGMCQWithDifficulty(RAGMCQ):
|
|
| 1194 |
correct_text = options[correct_key.strip()]
|
| 1195 |
else:
|
| 1196 |
correct_text = payload.get("correct_text") or correct_key or ""
|
| 1197 |
-
|
| 1198 |
diff_score, diff_label, components = self._estimate_difficulty_for_generation( # type: ignore
|
| 1199 |
-
q_text=q_text, options={k: str(v) for k,v in options.items()}, correct_text=str(correct_text), context_text=structured_context, concepts_used=concepts
|
| 1200 |
)
|
| 1201 |
|
| 1202 |
payload["độ khó"] = {"điểm": diff_score, "mức độ": diff_label}
|
|
@@ -1342,7 +1342,7 @@ class RAGMCQWithDifficulty(RAGMCQ):
|
|
| 1342 |
|
| 1343 |
#? change estimate
|
| 1344 |
diff_score, diff_label, components = self._estimate_difficulty_for_generation( # type: ignore
|
| 1345 |
-
q_text=q_text, options={k: str(v) for k,v in options.items()}, correct_text=str(correct_text), context_text=structured_context, concepts_used=concepts
|
| 1346 |
)
|
| 1347 |
|
| 1348 |
payload["độ khó"] = {"điểm": diff_score, "mức độ": diff_label}
|
|
@@ -1382,7 +1382,7 @@ class RAGMCQWithDifficulty(RAGMCQ):
|
|
| 1382 |
return 0.0
|
| 1383 |
mapped = (s + 1.0) / 2.0
|
| 1384 |
return max(0.0, min(1.0, mapped))
|
| 1385 |
-
|
| 1386 |
# embedding support
|
| 1387 |
emb_support = 0.0
|
| 1388 |
try:
|
|
|
|
| 604 |
}
|
| 605 |
|
| 606 |
return report
|
| 607 |
+
|
| 608 |
def connect_qdrant(self, url: str, api_key: str = None, prefer_grpc: bool = False):
|
| 609 |
if not _HAS_QDRANT:
|
| 610 |
raise RuntimeError("qdrant-client is not installed. Install with `pip install qdrant-client`.")
|
|
|
|
| 896 |
|
| 897 |
if "error" in list(mcq_block.keys()):
|
| 898 |
return output
|
| 899 |
+
|
| 900 |
for item in sorted(mcq_block.keys(), key=lambda x: int(x)):
|
| 901 |
qcount += 1
|
| 902 |
output[str(qcount)] = mcq_block[item]
|
|
|
|
| 996 |
res = self._retrieve(stmt, top_k=1)
|
| 997 |
except Exception:
|
| 998 |
res = []
|
| 999 |
+
|
| 1000 |
if res:
|
| 1001 |
raw_score = float(res[0][1])
|
| 1002 |
emb_support = safe_map_sim(raw_score)
|
|
|
|
| 1194 |
correct_text = options[correct_key.strip()]
|
| 1195 |
else:
|
| 1196 |
correct_text = payload.get("correct_text") or correct_key or ""
|
| 1197 |
+
|
| 1198 |
diff_score, diff_label, components = self._estimate_difficulty_for_generation( # type: ignore
|
| 1199 |
+
q_text=q_text, options={k: str(v) for k,v in options.items()}, correct_text=str(correct_text), context_text=structured_context, concepts_used=concepts
|
| 1200 |
)
|
| 1201 |
|
| 1202 |
payload["độ khó"] = {"điểm": diff_score, "mức độ": diff_label}
|
|
|
|
| 1342 |
|
| 1343 |
#? change estimate
|
| 1344 |
diff_score, diff_label, components = self._estimate_difficulty_for_generation( # type: ignore
|
| 1345 |
+
q_text=q_text, options={k: str(v) for k,v in options.items()}, correct_text=str(correct_text), context_text=structured_context, concepts_used=concepts
|
| 1346 |
)
|
| 1347 |
|
| 1348 |
payload["độ khó"] = {"điểm": diff_score, "mức độ": diff_label}
|
|
|
|
| 1382 |
return 0.0
|
| 1383 |
mapped = (s + 1.0) / 2.0
|
| 1384 |
return max(0.0, min(1.0, mapped))
|
| 1385 |
+
|
| 1386 |
# embedding support
|
| 1387 |
emb_support = 0.0
|
| 1388 |
try:
|