Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -76,7 +76,6 @@ class SolutionResponse(BaseModel):
|
|
| 76 |
|
| 77 |
@app.post("/get-solution", response_model=SolutionResponse)
|
| 78 |
def get_legal_solution(request: QueryRequest):
|
| 79 |
-
# ** FIX: Check for None explicitly as required by pymongo **
|
| 80 |
if model is None or tokenizer is None or collection is None:
|
| 81 |
raise HTTPException(status_code=503, detail="Server resources are not ready. Check startup logs for errors.")
|
| 82 |
|
|
@@ -85,7 +84,9 @@ def get_legal_solution(request: QueryRequest):
|
|
| 85 |
logits = model(**inputs).logits
|
| 86 |
|
| 87 |
prediction_id = torch.argmax(logits, dim=1).item()
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
document = collection.find_one({"intent": predicted_intent})
|
| 91 |
solution = document["answer"] if document and "answer" in document else "No specific solution was found for this topic."
|
|
|
|
| 76 |
|
| 77 |
@app.post("/get-solution", response_model=SolutionResponse)
|
| 78 |
def get_legal_solution(request: QueryRequest):
|
|
|
|
| 79 |
if model is None or tokenizer is None or collection is None:
|
| 80 |
raise HTTPException(status_code=503, detail="Server resources are not ready. Check startup logs for errors.")
|
| 81 |
|
|
|
|
| 84 |
logits = model(**inputs).logits
|
| 85 |
|
| 86 |
prediction_id = torch.argmax(logits, dim=1).item()
|
| 87 |
+
|
| 88 |
+
# ** FIX: Use the intent_map created from CSVs to get the human-readable label **
|
| 89 |
+
predicted_intent = intent_map.get(prediction_id, "Unknown Intent")
|
| 90 |
|
| 91 |
document = collection.find_one({"intent": predicted_intent})
|
| 92 |
solution = document["answer"] if document and "answer" in document else "No specific solution was found for this topic."
|