WORKWITHSHAFISK commited on
Commit
110367c
·
verified ·
1 Parent(s): 2848dc6

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +36 -2
api.py CHANGED
@@ -1,12 +1,13 @@
1
  from fastapi import FastAPI, File, UploadFile, HTTPException, Form
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import JSONResponse
4
- from pydantic import BaseModel, Field
5
  from typing import Optional, List, Dict, Any
6
  import pandas as pd
7
  import io
8
  import json
9
  from backend import RegexClassifier
 
10
 
11
  # Initialize FastAPI app
12
  app = FastAPI(
@@ -82,6 +83,10 @@ class ConfluenceRequest(BaseModel):
82
  class PDFPageRequest(BaseModel):
83
  page_number: int = 0
84
 
 
 
 
 
85
  # ==================== HELPER FUNCTIONS ====================
86
 
87
  def validate_file_size(file: UploadFile):
@@ -695,6 +700,35 @@ async def scan_confluence(request: ConfluenceRequest):
695
  except Exception as e:
696
  raise HTTPException(status_code=500, detail=f"Confluence scan failed: {str(e)}")
697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
698
  # ==================== HEALTH CHECK ====================
699
 
700
  @app.get("/")
@@ -723,4 +757,4 @@ async def health_check():
723
 
724
  if __name__ == "__main__":
725
  import uvicorn
726
- uvicorn.run(app, host="0.0.0.0", port=7860) # HuggingFace Spaces default port
 
1
  from fastapi import FastAPI, File, UploadFile, HTTPException, Form
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import JSONResponse
4
+ from pydantic import BaseModel, Field, EmailStr
5
  from typing import Optional, List, Dict, Any
6
  import pandas as pd
7
  import io
8
  import json
9
  from backend import RegexClassifier
10
+ from email_service import send_welcome_email
11
 
12
  # Initialize FastAPI app
13
  app = FastAPI(
 
83
  class PDFPageRequest(BaseModel):
84
  page_number: int = 0
85
 
86
+ class WelcomeEmailRequest(BaseModel):
87
+ name: str = Field(..., description="User's name")
88
+ email: EmailStr = Field(..., description="User's email address")
89
+
90
  # ==================== HELPER FUNCTIONS ====================
91
 
92
  def validate_file_size(file: UploadFile):
 
700
  except Exception as e:
701
  raise HTTPException(status_code=500, detail=f"Confluence scan failed: {str(e)}")
702
 
703
+ # ==================== EMAIL FUNCTIONALITY ====================
704
+
705
+ @app.post("/api/send-welcome")
706
+ async def send_welcome(request: WelcomeEmailRequest):
707
+ """
708
+ Send a welcome email to a new user.
709
+ This endpoint is called by the frontend after a user submits the contact form.
710
+ """
711
+ try:
712
+ # Send the welcome email
713
+ success = send_welcome_email(request.name, request.email)
714
+
715
+ if success:
716
+ return JSONResponse(content={
717
+ "success": True,
718
+ "message": f"Welcome email sent to {request.email}"
719
+ })
720
+ else:
721
+ raise HTTPException(
722
+ status_code=500,
723
+ detail="Failed to send welcome email. SMTP configuration may be missing."
724
+ )
725
+
726
+ except Exception as e:
727
+ raise HTTPException(
728
+ status_code=500,
729
+ detail=f"Email sending failed: {str(e)}"
730
+ )
731
+
732
  # ==================== HEALTH CHECK ====================
733
 
734
  @app.get("/")
 
757
 
758
  if __name__ == "__main__":
759
  import uvicorn
760
+ uvicorn.run(app, host="0.0.0.0", port=7860) # HuggingFace Spaces default port