Spaces:
Runtime error
Runtime error
Commit
·
81c6189
1
Parent(s):
4b5415a
deploy
Browse files- __pycache__/main.cpython-313.pyc +0 -0
- models/__pycache__/model_loader.cpython-313.pyc +0 -0
- routes/__pycache__/sms_router.cpython-313.pyc +0 -0
- routes/sms_router.py +6 -0
- schemas/__pycache__/schema.cpython-313.pyc +0 -0
- service/__pycache__/embedded_service.cpython-313.pyc +0 -0
- service/prediction_service.py +27 -4
__pycache__/main.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-313.pyc and b/__pycache__/main.cpython-313.pyc differ
|
|
|
models/__pycache__/model_loader.cpython-313.pyc
CHANGED
|
Binary files a/models/__pycache__/model_loader.cpython-313.pyc and b/models/__pycache__/model_loader.cpython-313.pyc differ
|
|
|
routes/__pycache__/sms_router.cpython-313.pyc
CHANGED
|
Binary files a/routes/__pycache__/sms_router.cpython-313.pyc and b/routes/__pycache__/sms_router.cpython-313.pyc differ
|
|
|
routes/sms_router.py
CHANGED
|
@@ -44,4 +44,10 @@ async def calculate_similarity(similarity_request: SimilarityRequest):
|
|
| 44 |
@router.post("/predict_label/", response_model=PredictionResponse)
|
| 45 |
async def predict_sms_label(prediction_request: PredictionRequest):
|
| 46 |
label, probability = predict_label(prediction_request.message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return PredictionResponse(label=label, probability=probability)
|
|
|
|
|
|
| 44 |
@router.post("/predict_label/", response_model=PredictionResponse)
|
| 45 |
async def predict_sms_label(prediction_request: PredictionRequest):
|
| 46 |
label, probability = predict_label(prediction_request.message)
|
| 47 |
+
|
| 48 |
+
# Handle prediction errors
|
| 49 |
+
if label == "Error":
|
| 50 |
+
raise HTTPException(status_code=500, detail="Prediction failed.")
|
| 51 |
+
|
| 52 |
return PredictionResponse(label=label, probability=probability)
|
| 53 |
+
|
schemas/__pycache__/schema.cpython-313.pyc
CHANGED
|
Binary files a/schemas/__pycache__/schema.cpython-313.pyc and b/schemas/__pycache__/schema.cpython-313.pyc differ
|
|
|
service/__pycache__/embedded_service.cpython-313.pyc
CHANGED
|
Binary files a/service/__pycache__/embedded_service.cpython-313.pyc and b/service/__pycache__/embedded_service.cpython-313.pyc differ
|
|
|
service/prediction_service.py
CHANGED
|
@@ -23,7 +23,30 @@ else:
|
|
| 23 |
|
| 24 |
# Define predict_label function
|
| 25 |
def predict_label(text):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Define predict_label function
|
| 25 |
def predict_label(text):
|
| 26 |
+
try:
|
| 27 |
+
# Ensure input is a list for the model
|
| 28 |
+
if not isinstance(text, list):
|
| 29 |
+
text = [text]
|
| 30 |
+
|
| 31 |
+
# Generate embeddings
|
| 32 |
+
embeddings = model.encode(text)
|
| 33 |
+
|
| 34 |
+
# Ensure embeddings are in the correct shape
|
| 35 |
+
if len(embeddings) == 0:
|
| 36 |
+
raise ValueError("No embeddings generated.")
|
| 37 |
+
|
| 38 |
+
# Predict using the logistic regression model
|
| 39 |
+
prediction = clf.predict(embeddings)
|
| 40 |
+
probability = clf.predict_proba(embeddings).max()
|
| 41 |
+
|
| 42 |
+
# Convert label to string ("0" or "1")
|
| 43 |
+
label = str(prediction[0])
|
| 44 |
+
|
| 45 |
+
# Return label and probability
|
| 46 |
+
return label, float(probability)
|
| 47 |
+
|
| 48 |
+
except Exception as e:
|
| 49 |
+
# Log the exception for debugging
|
| 50 |
+
print(f"Error in predict_label: {e}")
|
| 51 |
+
return "Error", 0.0
|
| 52 |
+
|