LT360 commited on
Commit ·
eccd941
1
Parent(s): beecd3e
Update CORS
Browse files- app/main.py +14 -6
app/main.py
CHANGED
|
@@ -2,19 +2,27 @@ from fastapi import FastAPI
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import os
|
| 4 |
import subprocess
|
|
|
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from typing import List, Tuple, Optional
|
| 7 |
from .ml import get_model_prediction, check_model_status
|
| 8 |
|
| 9 |
app = FastAPI(title="AI-Powered Phishing Email Detection System")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Define allowed origins for CORS
|
| 12 |
-
origins = [
|
| 13 |
-
"https://ai-powered-phishing-email-detection-system.vercel.app",
|
| 14 |
-
"http://localhost:3000",
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
]
|
| 19 |
|
| 20 |
app.add_middleware(
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
+
import re # Import the 're' module for regular expressions
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from typing import List, Tuple, Optional
|
| 8 |
from .ml import get_model_prediction, check_model_status
|
| 9 |
|
| 10 |
app = FastAPI(title="AI-Powered Phishing Email Detection System")
|
| 11 |
|
| 12 |
+
# Determine your specific Hugging Face Space direct URL
|
| 13 |
+
# Example: "https://username-spacename.hf.space"
|
| 14 |
+
HF_SPACE_DIRECT_URL = "https://lleratodev-multinomial-nb-phishing-email-detection-api.hf.space"
|
| 15 |
+
HF_SPACE_OLD_URL = "https://huggingface.co/spaces/lleratodev/multinomial-nb-phishing-email-detection-api"
|
| 16 |
+
|
| 17 |
# Define allowed origins for CORS
|
| 18 |
+
origins = [
|
| 19 |
+
"https://ai-powered-phishing-email-detection-system.vercel.app", # Our Next.js frontend hosted on Vercel
|
| 20 |
+
"http://localhost:3000", # Local development
|
| 21 |
+
HF_SPACE_DIRECT_URL, # Specific direct URL for Hugging Face Space
|
| 22 |
+
HF_SPACE_OLD_URL, # Older Hugging Face Space URL
|
| 23 |
+
# Regex to match any other *.hf.space subdomains if needed.
|
| 24 |
+
# This matches https://<any-subdomain(s)>.hf.space
|
| 25 |
+
re.compile(r"https://.+\.hf\.space"),
|
| 26 |
]
|
| 27 |
|
| 28 |
app.add_middleware(
|