Spaces:
Runtime error
Runtime error
import asyncio | |
from fastapi import FastAPI, UploadFile, WebSocket, WebSocketDisconnect | |
from fastapi.responses import FileResponse | |
from caesarfrenchllm import CaesarFrenchLLM | |
import uvicorn | |
app = FastAPI() | |
caesarmodel = CaesarFrenchLLM() | |
def caesaraihome(): | |
return "Welcome to CaesarAI's API's and CaesarAINL." | |
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()) |