Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
a0f1fda
1
Parent(s):
aaceb02
added prediction
Browse files
src/api/__pycache__/main.cpython-312.pyc
CHANGED
Binary files a/src/api/__pycache__/main.cpython-312.pyc and b/src/api/__pycache__/main.cpython-312.pyc differ
|
|
src/api/main.py
CHANGED
@@ -12,14 +12,18 @@ def home():
|
|
12 |
model = encoding_model.train_model()
|
13 |
return {"message": "Welcome to Prediction Hub"}
|
14 |
|
15 |
-
@app.get("/
|
16 |
-
def
|
17 |
try:
|
18 |
dimention = encoding_model.get_label(message)
|
19 |
return dimention
|
20 |
except Exception as e:
|
21 |
return f"Unable to fetch the data {e}"
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
12 |
model = encoding_model.train_model()
|
13 |
return {"message": "Welcome to Prediction Hub"}
|
14 |
|
15 |
+
@app.get("/dimention")
|
16 |
+
def display_dimention(message : str = "Hello World"):
|
17 |
try:
|
18 |
dimention = encoding_model.get_label(message)
|
19 |
return dimention
|
20 |
except Exception as e:
|
21 |
return f"Unable to fetch the data {e}"
|
22 |
|
23 |
+
@app.get("/prediction")
|
24 |
+
def display_prediction(message : str = "Give me a sms to predict"):
|
25 |
+
try:
|
26 |
+
prediction = encoding_model.get_prediction(message)
|
27 |
+
return prediction
|
28 |
+
except Exception as e:
|
29 |
+
return f"Unable to fetch the data {e}"
|
src/modules/__pycache__/encoding_model.cpython-312.pyc
CHANGED
Binary files a/src/modules/__pycache__/encoding_model.cpython-312.pyc and b/src/modules/__pycache__/encoding_model.cpython-312.pyc differ
|
|
src/modules/encoding_model.py
CHANGED
@@ -35,8 +35,17 @@ def get_label(message):
|
|
35 |
new_embeddings = encoding_model.encode([message])
|
36 |
array = np.array(new_embeddings)[0].tolist()
|
37 |
|
38 |
-
prediction = logreg_model.predict(new_embeddings)
|
39 |
|
40 |
no_of_dimensions = len(new_embeddings[0])
|
41 |
dimension_df = pd.DataFrame(array, columns=["Dimension"])
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
new_embeddings = encoding_model.encode([message])
|
36 |
array = np.array(new_embeddings)[0].tolist()
|
37 |
|
38 |
+
prediction = logreg_model.predict(new_embeddings).tolist()
|
39 |
|
40 |
no_of_dimensions = len(new_embeddings[0])
|
41 |
dimension_df = pd.DataFrame(array, columns=["Dimension"])
|
42 |
+
|
43 |
+
return {"Prediction_Dimension": {no_of_dimensions: dimension_df}}
|
44 |
+
|
45 |
+
def get_prediction(message):
|
46 |
+
if logreg_model is None:
|
47 |
+
raise ValueError("Model has not been trained yet. Please call train_model first.")
|
48 |
+
|
49 |
+
new_embeddings = encoding_model.encode([message])
|
50 |
+
prediction = logreg_model.predict(new_embeddings).tolist()
|
51 |
+
return prediction
|
src/modules/logistic_regression.py
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
# import pandas as pd
|
2 |
-
# from sklearn.model_selection import train_test_split
|
3 |
-
# from sklearn.linear_model import LogisticRegression
|
4 |
-
# from sklearn.metrics import accuracy_score, classification_report
|
5 |
-
# import numpy as np
|
6 |
-
# import os
|
7 |
-
# import sys
|
8 |
-
# src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "src"))
|
9 |
-
# sys.path.append(src_directory)
|
10 |
-
# from data import sample_data
|
11 |
-
# from modules import encoding_model
|
12 |
-
|
13 |
-
# file_path = r"src/data/sms_process_data_main.xlsx"
|
14 |
-
# df = sample_data.get_data_frame(file_path)
|
15 |
-
|
16 |
-
# def get_label(message):
|
17 |
-
# from sentence_transformers import SentenceTransformer
|
18 |
-
# # model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
|
19 |
-
# X_train, X_test, y_train, y_test = train_test_split(df['MessageText'], df['label'], test_size=0.2, random_state=42)
|
20 |
-
# X_train_embeddings = encoding_model.model.encode(X_train.tolist())
|
21 |
-
# models = LogisticRegression(max_iter=100)
|
22 |
-
# models.fit(X_train_embeddings, y_train)
|
23 |
-
# new_embeddings = encoding_model.model.encode(message)
|
24 |
-
# no_of_dimention = len(new_embeddings)
|
25 |
-
# array = np.array(new_embeddings).tolist()
|
26 |
-
# # new_predictions = models.predict(new_embeddings)
|
27 |
-
# dimention = pd.DataFrame(array,columns=["Dimention"])
|
28 |
-
# return {"Prediction_Dimention":{no_of_dimention: dimention}}
|
29 |
-
|
30 |
-
# def create_embending(message:str):
|
31 |
-
# embending_message = encoding_model.model.encode(message)
|
32 |
-
# result = np.array(embending_message).tolist()
|
33 |
-
# return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/schemas/schemas.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
class CosineSimilarity(BaseModel):
|
4 |
+
text_1 : str
|
5 |
+
text_1 : str
|