Spaces:
Sleeping
Sleeping
File size: 1,487 Bytes
baa1558 | 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 | import asyncio
import os
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from pydantic import BaseModel
from caesarinfer import CaesarNL
app = FastAPI()
CURRENT_DIR = os.path.realpath(__file__).replace(f"/main.py","")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # can alter with time
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class CaesarAINLModel(BaseModel):
caesarapi: str
@app.get("/")
def caesarhome():
return "Caeser: How can I help you sir?"
@app.get("/caesarapi")
def caesarapiget():
return "Caeser: Hello sir, this is the CaesarAIAPI"
@app.post("/caesarapi")
def caesarapi(caesarapijson: CaesarAINLModel):
try:
caesarapijson = dict(caesarapijson)
print("Caesar Processing...")
caesarResponse,intents = CaesarNL.run([caesarapijson["caesarapi"]])
print("Caesar Processed.")
print(caesarResponse,"intent:",intents)
return {"caesarmessage":{"caesarResponse":caesarResponse,"intent":intents}}
except Exception as ex:
return {"error":f"{type(ex)}-{ex}"}
async def main():
config = uvicorn.Config("main:app", port=7860, log_level="info",host="0.0.0.0",reload=True)
server = uvicorn.Server(config)
await server.serve()
if __name__ == "__main__":
asyncio.run(main())
|