Spaces:
Sleeping
Sleeping
Commit
·
d5114e6
1
Parent(s):
b4f3263
refactor: conform to vertex ai requirements
Browse files- prediction.py +20 -10
- requirements.txt +8 -0
prediction.py
CHANGED
|
@@ -7,6 +7,7 @@ from main_model import PredictMainModel
|
|
| 7 |
import torch.nn as nn
|
| 8 |
import torch
|
| 9 |
import numpy as np
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
|
@@ -19,15 +20,22 @@ class PredictRequest(BaseModel):
|
|
| 19 |
letter_click_counts: dict[str, int]
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@app.post("/predict")
|
| 23 |
-
async def predict(request:
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
hypothesis = BaseModelHypothesis()
|
| 33 |
features_normalized_text_length = hypothesis.calculate_normalized_text_length_features(
|
|
@@ -51,7 +59,9 @@ async def predict(request: PredictRequest):
|
|
| 51 |
secondary_model_features)
|
| 52 |
|
| 53 |
return {
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
}
|
|
|
|
| 7 |
import torch.nn as nn
|
| 8 |
import torch
|
| 9 |
import numpy as np
|
| 10 |
+
from typing import List
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
| 20 |
letter_click_counts: dict[str, int]
|
| 21 |
|
| 22 |
|
| 23 |
+
class RequestModel(BaseModel):
|
| 24 |
+
instances: List[PredictRequest]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
@app.post("/predict")
|
| 28 |
+
async def predict(request: RequestModel):
|
| 29 |
+
responses = [process_instance(data) for data in request.instances]
|
| 30 |
+
return {"predictions": responses}
|
| 31 |
+
|
| 32 |
|
| 33 |
+
def process_instance(data: PredictRequest):
|
| 34 |
+
question = data.question
|
| 35 |
+
answer = data.answer
|
| 36 |
+
backspace_count = data.backspace_count
|
| 37 |
+
typing_duration = data.typing_duration
|
| 38 |
+
letter_click_counts = data.letter_click_counts
|
| 39 |
|
| 40 |
hypothesis = BaseModelHypothesis()
|
| 41 |
features_normalized_text_length = hypothesis.calculate_normalized_text_length_features(
|
|
|
|
| 59 |
secondary_model_features)
|
| 60 |
|
| 61 |
return {
|
| 62 |
+
"prediction_class": "AI" if secondary_model_prediction == 1 else "HUMAN",
|
| 63 |
+
"details": {
|
| 64 |
+
"main_model_probability": main_model_probability,
|
| 65 |
+
"final_prediction": secondary_model_prediction
|
| 66 |
+
}
|
| 67 |
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
nltk
|
| 3 |
+
vaderSentiment
|
| 4 |
+
pandas
|
| 5 |
+
textstat
|
| 6 |
+
scikit-learn==1.4.1.post1
|
| 7 |
+
transformers
|
| 8 |
+
fastapi
|