Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
c82e328
1
Parent(s):
fb3d17d
Added project
Browse files- .gitignore +1 -0
- requirements.txt +5 -0
- src/api/__pycache__/main.cpython-312.pyc +0 -0
- src/api/main.py +24 -0
- src/data/__pycache__/sample_data.cpython-312.pyc +0 -0
- src/data/sample_data.py +5 -0
- src/data/sms_process_data_main.xlsx +0 -0
- src/modules/__pycache__/logistic_regression.cpython-312.pyc +0 -0
- src/modules/logistic_regression.py +26 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.venv
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
scikit-learn
|
3 |
+
sentence_transformers
|
4 |
+
openpyxl
|
5 |
+
fastapi[standard]
|
src/api/__pycache__/main.cpython-312.pyc
ADDED
Binary file (1.41 kB). View file
|
|
src/api/main.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "src"))
|
5 |
+
sys.path.append(src_directory)
|
6 |
+
from modules import logistic_regression
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
@app.get("/")
|
11 |
+
def home():
|
12 |
+
return {"message": "Welcome to Prediction Hub"}
|
13 |
+
|
14 |
+
@app.get("/predict")
|
15 |
+
def display_prediction(message : str = "Hello World"):
|
16 |
+
try:
|
17 |
+
dimention = logistic_regression.get_label(message)
|
18 |
+
# dimention = message
|
19 |
+
return {"message" : dimention}
|
20 |
+
except Exception as e:
|
21 |
+
return f"Unable to fetch the data {e}"
|
22 |
+
|
23 |
+
# x = display_prediction()
|
24 |
+
# print(type(x))
|
src/data/__pycache__/sample_data.cpython-312.pyc
ADDED
Binary file (434 Bytes). View file
|
|
src/data/sample_data.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
def get_data_frame(file_path):
|
4 |
+
df = pd.read_excel(file_path)
|
5 |
+
return df
|
src/data/sms_process_data_main.xlsx
ADDED
Binary file (42.2 kB). View file
|
|
src/modules/__pycache__/logistic_regression.cpython-312.pyc
ADDED
Binary file (2.08 kB). View file
|
|
src/modules/logistic_regression.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
import pandas as pd
|
3 |
+
from sklearn.model_selection import train_test_split
|
4 |
+
from sklearn.linear_model import LogisticRegression
|
5 |
+
from sklearn.metrics import accuracy_score, classification_report
|
6 |
+
import numpy as np
|
7 |
+
import os
|
8 |
+
import sys
|
9 |
+
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "src"))
|
10 |
+
sys.path.append(src_directory)
|
11 |
+
from data import sample_data
|
12 |
+
|
13 |
+
file_path = r"D:\Jupyter_project\sms_process_data_main.xlsx"
|
14 |
+
df = sample_data.get_data_frame(file_path)
|
15 |
+
|
16 |
+
def get_label(message):
|
17 |
+
X_train, X_test, y_train, y_test = train_test_split(df['MessageText'], df['label'], test_size=0.2, random_state=42)
|
18 |
+
model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
|
19 |
+
X_train_embeddings = model.encode(X_train.tolist())
|
20 |
+
models = LogisticRegression(max_iter=100)
|
21 |
+
models.fit(X_train_embeddings, y_train)
|
22 |
+
new_embeddings = model.encode(message)
|
23 |
+
array = np.array(new_embeddings).tolist()
|
24 |
+
# new_predictions = models.predict(new_embeddings)
|
25 |
+
dimention = pd.DataFrame(array,columns=["Dimention"])
|
26 |
+
return dimention
|