Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, HTTPException | |
| from services.sms_service import predict_label, compute_cosine_similarity, get_embedding | |
| from schemas.input_schemas import CosineSimilarityInput, MessageInput, EmbeddingInput | |
| app = FastAPI() | |
| # π 1οΈβ£ Homepage Endpoint | |
| async def home(): | |
| return {"message": "Welcome to SMS Classification API"} | |
| # π’ 2οΈβ£ Cosine Similarity Endpoint | |
| 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 | |
| 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οΈβ£ Get Embedding from Sentence Transformer | |
| async def get_embedding(input_data: EmbeddingInput): | |
| try: | |
| return await get_embedding(input_data.message) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Error computing embeddings: {str(e)}") | |