-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (22 loc) · 731 Bytes
/
main.py
File metadata and controls
29 lines (22 loc) · 731 Bytes
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
# main.py
from fastapi import FastAPI, Request
from pydantic import BaseModel
from summarize import summarize_policy
import uvicorn
import json #edited
app = FastAPI()
class PolicyRequest(BaseModel):
url: str
@app.post("/summarize")
async def summarize(request: PolicyRequest):
try:
summary = await summarize_policy(request.url)
return {"summary": json.loads(summary)} ## edited
except Exception as e:
import traceback
print("ERROR:", str(e))
traceback.print_exc()
return {"error": str(e) or "Unknown error"}
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8000)) # using 8000 locally
uvicorn.run("main:app", host="0.0.0.0", port=port)