Delete main.py
Browse files
main.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
from fastapi import FastAPI, Request
|
2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
3 |
-
import asyncio
|
4 |
-
from Linlada import Chatbot, ConversationStyle
|
5 |
-
|
6 |
-
app = FastAPI()
|
7 |
-
|
8 |
-
app.add_middleware(
|
9 |
-
CORSMiddleware,
|
10 |
-
allow_origins=["*"],
|
11 |
-
allow_methods=["*"],
|
12 |
-
allow_headers=["*"],
|
13 |
-
allow_credentials=True,
|
14 |
-
)
|
15 |
-
|
16 |
-
async def generate(prompt):
|
17 |
-
bot = await Chatbot.create()
|
18 |
-
result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise)
|
19 |
-
return result
|
20 |
-
|
21 |
-
|
22 |
-
@app.get("/")
|
23 |
-
def read_root():
|
24 |
-
return "Hello, I'm Linlada"
|
25 |
-
|
26 |
-
@app.get("/test/{hello}")
|
27 |
-
def hi(hello: str):
|
28 |
-
return {"text": hello}
|
29 |
-
|
30 |
-
|
31 |
-
@app.post('/linlada')
|
32 |
-
async def generate_image_route(request: Request):
|
33 |
-
data = await request.json()
|
34 |
-
prompt = data['prompt']
|
35 |
-
result = await generate(prompt)
|
36 |
-
return result
|
37 |
-
|
38 |
-
|
39 |
-
@app.get('/linlada2/{prompt}')
|
40 |
-
def generate_image_route(prompt: str):
|
41 |
-
loop = asyncio.new_event_loop()
|
42 |
-
asyncio.set_event_loop(loop)
|
43 |
-
result = loop.run_until_complete(generate(prompt))
|
44 |
-
loop.close()
|
45 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|