File size: 1,038 Bytes
c7184b6
e5bc3c5
67780da
 
b8a907e
 
 
d2978b4
 
 
 
 
 
 
 
67780da
 
 
 
 
f17ee59
b8a907e
 
e0b6fc3
61d0503
ff2c49e
61d0503
6e99035
bcf8e55
c7184b6
 
0cda19c
 
c7184b6
1c607f3
f17ee59
c7184b6
9d9aae5
d3b9111
67780da
 
 
 
 
 
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
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