File size: 965 Bytes
02a9316
54bac2e
02a9316
aae42e1
54bac2e
 
 
02a9316
54bac2e
 
02a9316
 
 
54bac2e
 
 
 
 
 
02a9316
54bac2e
 
02a9316
 
 
 
aae42e1
 
 
 
 
02a9316
 
 
 
 
 
 
 
54bac2e
02a9316
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
from fastapi import FastAPI, Query
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse

app = FastAPI()

# CORS setup
origins = [
    "http://localhost:3000",
    "http://localhost:8000",
    "localhost:8000",
    "https://your-space-name.hf.space",
]
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Mount static files
app.mount("/static", StaticFiles(directory="app/build", html=True), name="static")


# Serve index.html at the root
@app.get("/")
def read_root():
    return FileResponse("app/build/index.html")

# Define API route
@app.get("/api/sum_of_lengths")
def sum_of_lengths(word1: str = Query(...), word2: str = Query(...)):
    return {"sum": len(word1) + len(word2)}


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)