from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware import asyncio from Linlada import Chatbot, ConversationStyle app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"], allow_credentials=True, ) async def generate(prompt): bot = await Chatbot.create() result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise) return result @app.get("/") def read_root(): return "Hello, I'm Linlada" @app.get("/test/{hello}") def hi(hello: str): return {"text": hello} @app.post('/linlada') async def generate_image_route(request: Request): data = await request.json() prompt = data['prompt'] result = await generate(prompt) return result @app.get('/linlada2/{prompt}') def generate_image_route(prompt: str): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) result = loop.run_until_complete(generate(prompt)) loop.close() return result