Spaces:
Sleeping
Sleeping
[email protected]
commited on
Commit
·
3f0e2a9
1
Parent(s):
6deb4c6
initial commit
Browse files- __pycache__/main.cpython-310.pyc +0 -0
- main.py +27 -0
- requirements.txt +4 -0
- sms_classifier_model.pkl +3 -0
__pycache__/main.cpython-310.pyc
ADDED
Binary file (1.03 kB). View file
|
|
main.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import joblib
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
model = SentenceTransformer(
|
7 |
+
'Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
|
8 |
+
|
9 |
+
|
10 |
+
@app.get("/")
|
11 |
+
def root():
|
12 |
+
return {"message": "Welcom to FastAPI with Logistic Regression"}
|
13 |
+
|
14 |
+
|
15 |
+
@app.post("/dimensions/")
|
16 |
+
def get_dimension(message: str):
|
17 |
+
message_embedding = model.encode([message])
|
18 |
+
return {"dimensions": message_embedding.shape[1]}
|
19 |
+
|
20 |
+
|
21 |
+
@app.post("/classify/")
|
22 |
+
def get_dimension(message: str):
|
23 |
+
loaded_model = joblib.load('sms_classifier_model.pkl')
|
24 |
+
message_embedding = model.encode([message])
|
25 |
+
prediction = loaded_model.predict(message_embedding)
|
26 |
+
return {"Predicted Category": f"{prediction[0]}"}
|
27 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.115.5
|
2 |
+
fastapi-cli==0.0.7
|
3 |
+
joblib==1.4.2
|
4 |
+
sentence-transformers==3.4.1
|
sms_classifier_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d62c231572d4bb143da1a4fbe59ef0330779f3961331fbf3c854a92637509cd1
|
3 |
+
size 7215
|