Update main.py
Browse files
main.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
import asyncio
|
4 |
from Linlada import Chatbot, ConversationStyle
|
5 |
-
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
6 |
-
import torch
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
@@ -20,16 +18,6 @@ async def generate(prompt):
|
|
20 |
result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise)
|
21 |
return result
|
22 |
|
23 |
-
def dummy(images, **kwargs):
|
24 |
-
return images, False
|
25 |
-
|
26 |
-
async def generate_image(prompt):
|
27 |
-
model_id = "runwayml/stable-diffusion-v1-5"
|
28 |
-
pipe = await StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
29 |
-
pipe = pipe.to("cuda")
|
30 |
-
pipe.safety_checker = dummy
|
31 |
-
image = await pipe(prompt).images[0]
|
32 |
-
return image
|
33 |
|
34 |
@app.get("/")
|
35 |
def read_root():
|
@@ -39,15 +27,18 @@ def read_root():
|
|
39 |
def hi(hello: str):
|
40 |
return {"text": hello}
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
loop = asyncio.new_event_loop()
|
45 |
asyncio.set_event_loop(loop)
|
46 |
-
result = loop.run_until_complete(
|
47 |
loop.close()
|
48 |
return result
|
49 |
-
|
50 |
-
@app.get('/
|
51 |
def generate_image_route(prompt: str):
|
52 |
loop = asyncio.new_event_loop()
|
53 |
asyncio.set_event_loop(loop)
|
|
|
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 |
|
|
|
18 |
result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise)
|
19 |
return result
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
@app.get("/")
|
23 |
def read_root():
|
|
|
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 |
loop = asyncio.new_event_loop()
|
36 |
asyncio.set_event_loop(loop)
|
37 |
+
result = loop.run_until_complete(generate(prompt))
|
38 |
loop.close()
|
39 |
return result
|
40 |
+
|
41 |
+
@app.get('/chat/{prompt}')
|
42 |
def generate_image_route(prompt: str):
|
43 |
loop = asyncio.new_event_loop()
|
44 |
asyncio.set_event_loop(loop)
|