Spaces:
Sleeping
Sleeping
Commit
·
8d0988b
1
Parent(s):
1f23e23
updated CORS
Browse files
main.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import Any, Dict, Optional, Tuple
|
|
| 8 |
from functools import lru_cache
|
| 9 |
|
| 10 |
from fastapi import FastAPI
|
|
|
|
| 11 |
from pydantic import BaseModel
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
from llama_cpp import Llama
|
|
@@ -43,6 +44,25 @@ GEN_LOCK = asyncio.Lock()
|
|
| 43 |
|
| 44 |
app = FastAPI(title="FADES Fallacy Detector (GGUF / llama.cpp)")
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# ----------------------------
|
| 47 |
# Request model
|
| 48 |
# ----------------------------
|
|
|
|
| 8 |
from functools import lru_cache
|
| 9 |
|
| 10 |
from fastapi import FastAPI
|
| 11 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from pydantic import BaseModel
|
| 13 |
from huggingface_hub import hf_hub_download
|
| 14 |
from llama_cpp import Llama
|
|
|
|
| 44 |
|
| 45 |
app = FastAPI(title="FADES Fallacy Detector (GGUF / llama.cpp)")
|
| 46 |
|
| 47 |
+
# ----------------------------
|
| 48 |
+
# CORS (for browser front-ends)
|
| 49 |
+
# ----------------------------
|
| 50 |
+
# Comma-separated list of allowed origins, or "*" to allow all.
|
| 51 |
+
_CORS_ORIGINS = os.getenv("CORS_ALLOW_ORIGINS", "*").strip()
|
| 52 |
+
if _CORS_ORIGINS == "*" or not _CORS_ORIGINS:
|
| 53 |
+
allow_origins = ["*"]
|
| 54 |
+
else:
|
| 55 |
+
allow_origins = [o.strip() for o in _CORS_ORIGINS.split(",") if o.strip()]
|
| 56 |
+
|
| 57 |
+
# Note: when allow_origins=["*"], allow_credentials must be False.
|
| 58 |
+
app.add_middleware(
|
| 59 |
+
CORSMiddleware,
|
| 60 |
+
allow_origins=allow_origins,
|
| 61 |
+
allow_credentials=False,
|
| 62 |
+
allow_methods=["*"],
|
| 63 |
+
allow_headers=["*"],
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
# ----------------------------
|
| 67 |
# Request model
|
| 68 |
# ----------------------------
|