File size: 1,657 Bytes
2e8db96 198515a 2e8db96 41f1ee1 2e8db96 41f1ee1 2e8db96 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles
#import numpy as np
import argparse
import os
import introspector_rdf
HOST = os.environ.get("API_URL", "0.0.0.0")
PORT = os.environ.get("PORT", 7860)
parser = argparse.ArgumentParser()
parser.add_argument("--host", default=HOST)
parser.add_argument("--port", type=int, default=PORT)
parser.add_argument("--reload", action="store_true", default=True)
parser.add_argument("--ssl_certfile")
parser.add_argument("--ssl_keyfile")
args = parser.parse_args()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/invert")
async def invert(text: str):
return {
"original": text,
"inverted": text[::-1],
}
@app.get("/data")
async def get_data():
data = introspector_rdf.data()
# data = {"data": [
# dict(
# subject="this",
# predicate="self_reference",
# _object="<SELF>",
# ),
# dict(
# subject="introspector_rdf",
# predicate="data",
# _object=rows,
# ),
# ]}
return JSONResponse(data)
app.mount("/", StaticFiles(directory="static", html=True), name="static")
if __name__ == "__main__":
import uvicorn
print(args)
uvicorn.run(
"app:app",
host=args.host,
port=args.port,
reload=args.reload,
ssl_certfile=args.ssl_certfile,
ssl_keyfile=args.ssl_keyfile,
)
|