File size: 1,343 Bytes
a0af9d5
ed1f32e
ba19e1d
a0af9d5
 
 
 
 
 
877a8c0
 
ed1f32e
 
ba19e1d
877a8c0
ed1f32e
877a8c0
ed1f32e
a0af9d5
ed1f32e
 
ba19e1d
a0af9d5
ed1f32e
a0af9d5
ed1f32e
a0af9d5
ed1f32e
 
ba19e1d
a0af9d5
ed1f32e
a0af9d5
ed1f32e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI, HTTPException
from services.sms_service import predict_label, compute_cosine_similarity, compute_embeddings
from schemas.input_schemas import CosineSimilarityInput, MessageInput, EmbeddingInput

app = FastAPI()

# πŸš€ 1️⃣ Homepage Endpoint
@app.get("/")
async def home():
    return {"message": "Welcome to SMS Classification API"}

# πŸ”’ 2️⃣ Cosine Similarity Endpoint
@app.post("/cosine_similarity")
async def get_cosine_similarity(input_data: CosineSimilarityInput):
    try:
        return await compute_cosine_similarity(input_data.text1, input_data.text2)
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error computing similarity: {str(e)}")

# πŸ“© 3️⃣ SMS Classification Endpoint
@app.post("/predict_label")
async def classify_message(input_data: MessageInput):
    try:
        return await predict_label(input_data.message)
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error predicting label: {str(e)}")

# πŸ“Š 4️⃣ Text Embedding Endpoint
@app.post("/compute_embeddings")
async def get_embeddings(input_data: EmbeddingInput):
    try:
        return await compute_embeddings(input_data.message)
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error computing embeddings: {str(e)}")