File size: 1,388 Bytes
5fcf356
2c451af
b551e0c
83ff685
7b62481
2c451af
600b195
83ff685
0d71d6f
83ff685
 
 
 
5fcf356
2e624f8
 
 
 
 
 
 
 
 
 
10f3a01
2e624f8
5ce8f68
13fd394
83ff685
3ce8c1f
83ff685
 
 
3ce8c1f
83ff685
 
 
 
 
 
 
2e624f8
83ff685
 
 
 
 
5fcf356
 
7b62481
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import asyncio
from fastapi import FastAPI, HTTPException, Security, Depends, Query
from fastapi.security import APIKeyHeader
from pydantic import BaseModel, Field, create_model
from typing import List, Optional
import json
import logging
from fastapi.middleware.cors import CORSMiddleware

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = FastAPI(
    title="FastAPI",
    version="0.1.0",
    servers=[
        {
            "url": "https://pvanand-doc-maker.hf.space",  # Your production URL
            "description": "Production server"
        }
    ]
)

from doc_maker import router as doc_maker_router
app.include_router(doc_maker_router, prefix="/api/v1")

# API key configuration
CHAT_AUTH_KEY = os.getenv("CHAT_AUTH_KEY")
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)

async def verify_api_key(api_key: str = Security(api_key_header)):
    if api_key != CHAT_AUTH_KEY:
        logger.warning("Invalid API key used")
        raise HTTPException(status_code=403, detail="Could not validate credentials")
    return api_key

# CORS middleware setup
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["GET", "POST"],
    allow_headers=["*"],
)

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)