Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import tempfile
|
|
| 7 |
from fastapi import FastAPI, Request
|
| 8 |
from fastapi.responses import JSONResponse
|
| 9 |
import uvicorn
|
|
|
|
| 10 |
|
| 11 |
# --- Load Model ---
|
| 12 |
try:
|
|
@@ -20,6 +21,18 @@ else:
|
|
| 20 |
# --- FastAPI App ---
|
| 21 |
app = FastAPI()
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# This is our dedicated, robust API endpoint
|
| 24 |
@app.post("/api/predict/")
|
| 25 |
async def predict_emotion_api(request: Request):
|
|
|
|
| 7 |
from fastapi import FastAPI, Request
|
| 8 |
from fastapi.responses import JSONResponse
|
| 9 |
import uvicorn
|
| 10 |
+
from fastapi.middleware.cors import CORSMiddleware # <--- 1. ADD THIS IMPORT
|
| 11 |
|
| 12 |
# --- Load Model ---
|
| 13 |
try:
|
|
|
|
| 21 |
# --- FastAPI App ---
|
| 22 |
app = FastAPI()
|
| 23 |
|
| 24 |
+
# --- 2. ADD THIS ENTIRE BLOCK ---
|
| 25 |
+
# This block adds the CORS middleware to allow your WordPress site to make requests.
|
| 26 |
+
app.add_middleware(
|
| 27 |
+
CORSMiddleware,
|
| 28 |
+
allow_origins=["https://tknassetshub.io"], # This gives your specific domain permission.
|
| 29 |
+
allow_credentials=True,
|
| 30 |
+
allow_methods=["*"],
|
| 31 |
+
allow_headers=["*"],
|
| 32 |
+
)
|
| 33 |
+
# ---------------------------------
|
| 34 |
+
|
| 35 |
+
|
| 36 |
# This is our dedicated, robust API endpoint
|
| 37 |
@app.post("/api/predict/")
|
| 38 |
async def predict_emotion_api(request: Request):
|