Update model.py
Browse files
model.py
CHANGED
@@ -1,37 +1,27 @@
|
|
1 |
-
import
|
2 |
-
from
|
3 |
-
from transformers import AutoModelForSequenceClassification
|
4 |
-
from utilities import preprocess_features, generate_recommendation
|
5 |
-
|
6 |
-
MODEL_NAME = "sathkrutha/deal-score-model" # Use your actual repo ID
|
7 |
-
SUMMARIZER_PATH = "t5-small" # Can use distilgpt2 or other summarizers
|
8 |
|
|
|
9 |
def load_model():
|
10 |
-
|
11 |
-
tokenizer = BertTokenizer.from_pretrained(MODEL_PATH)
|
12 |
-
summarizer = T5ForConditionalGeneration.from_pretrained(SUMMARIZER_PATH)
|
13 |
-
return model, tokenizer, summarizer
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
inputs = tokenizer(features["text"], return_tensors="pt")
|
18 |
-
|
19 |
-
with torch.no_grad():
|
20 |
-
outputs = model(**inputs)
|
21 |
-
score = round(outputs.logits[0][0].item() * 100)
|
22 |
-
confidence = torch.softmax(outputs.logits[0], dim=-1).max().item()
|
23 |
|
|
|
|
|
|
|
24 |
risk = (
|
25 |
"Low" if score > 75 else
|
26 |
-
"Medium" if score
|
27 |
"High"
|
28 |
)
|
29 |
|
30 |
-
recommendation = generate_recommendation(
|
31 |
|
32 |
return {
|
33 |
"score": score,
|
34 |
-
"confidence":
|
35 |
"risk": risk,
|
36 |
"recommendation": recommendation
|
37 |
}
|
|
|
1 |
+
import random
|
2 |
+
from utilities import prepare_text_input, generate_recommendation
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Mock objects (None used in mock version)
|
5 |
def load_model():
|
6 |
+
return None, None, None
|
|
|
|
|
|
|
7 |
|
8 |
+
def predict(data, model, tokenizer, summarizer):
|
9 |
+
text_input = prepare_text_input(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Simulated scoring logic
|
12 |
+
score = random.randint(45, 95)
|
13 |
+
confidence = round(random.uniform(0.6, 0.95), 2)
|
14 |
risk = (
|
15 |
"Low" if score > 75 else
|
16 |
+
"Medium" if score >= 55 else
|
17 |
"High"
|
18 |
)
|
19 |
|
20 |
+
recommendation = generate_recommendation(data)
|
21 |
|
22 |
return {
|
23 |
"score": score,
|
24 |
+
"confidence": confidence,
|
25 |
"risk": risk,
|
26 |
"recommendation": recommendation
|
27 |
}
|