Spaces:
Runtime error
Runtime error
File size: 1,053 Bytes
37cb9fa |
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 |
import asyncio
from fastapi import FastAPI, UploadFile, WebSocket, WebSocketDisconnect
from fastapi.responses import FileResponse
from caesarfrenchllm import CaesarFrenchLLM
import uvicorn
app = FastAPI()
caesarmodel = CaesarFrenchLLM()
@app.get("/")
def caesaraihome():
return "Welcome to CaesarAI's API's and CaesarAINL."
@app.websocket("/caesarfrenchllmws")
async def caesarfrenchllmws(websocket: WebSocket):
# listen for connections
await websocket.accept()
try:
while True:
contents = await websocket.receive_json()
textresp = caesarmodel.chat(contents["message"])
final_response = {"message":textresp}
await websocket.send_json(final_response) # sends the buffer as bytes
except WebSocketDisconnect:
print("Client disconnected")
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()) |