Update main.py
Browse files
main.py
CHANGED
@@ -19,6 +19,18 @@ async def generate(prompt):
|
|
19 |
result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise)
|
20 |
return result
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
@app.get("/")
|
23 |
def read_root():
|
24 |
return "Hello, I'm Linlada"
|
@@ -29,8 +41,11 @@ def hi(hello: str):
|
|
29 |
|
30 |
@app.get("/image/{image}")
|
31 |
def img(image: str):
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
@app.get('/linlada/{prompt}')
|
36 |
def generate_image_route(prompt: str):
|
|
|
19 |
result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise)
|
20 |
return result
|
21 |
|
22 |
+
def dummy(images, **kwargs):
|
23 |
+
return images, False
|
24 |
+
|
25 |
+
async def generate_image(prompt):
|
26 |
+
model_id = "SG161222/Realistic_Vision_V1.4"
|
27 |
+
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
28 |
+
pipe = await StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, 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():
|
36 |
return "Hello, I'm Linlada"
|
|
|
41 |
|
42 |
@app.get("/image/{image}")
|
43 |
def img(image: str):
|
44 |
+
loop = asyncio.new_event_loop()
|
45 |
+
asyncio.set_event_loop(loop)
|
46 |
+
result = loop.run_until_complete(generate_image(image))
|
47 |
+
loop.close()
|
48 |
+
return result
|
49 |
|
50 |
@app.get('/linlada/{prompt}')
|
51 |
def generate_image_route(prompt: str):
|