test 5
Browse files- app.py +17 -24
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,18 +1,15 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
from torch import autocast
|
4 |
-
import requests
|
5 |
-
import torch
|
6 |
from PIL import Image
|
7 |
-
from io import BytesIO
|
8 |
-
|
9 |
from diffusers import StableDiffusionImg2ImgPipeline
|
10 |
|
11 |
# load the pipeline
|
12 |
device = "cuda"
|
13 |
model_id_or_path = "CompVis/stable-diffusion-v1-4"
|
14 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
15 |
-
|
16 |
revision="fp16",
|
17 |
torch_dtype=torch.float16,
|
18 |
use_auth_token='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'
|
@@ -22,29 +19,25 @@ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
|
22 |
pipe = pipe.to(device)
|
23 |
|
24 |
def diffuse(x, param):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
import numpy as np
|
41 |
-
import gradio as gr
|
42 |
|
43 |
def flip_image(x, param):
|
44 |
return [np.fliplr(x), 'функция приняла на вход ' + param]
|
45 |
|
46 |
with gr.Blocks() as demo:
|
47 |
-
|
48 |
gr.Markdown("Слово 'Санкт-Петербург'")
|
49 |
with gr.Tab("Санкт-Петербург"):
|
50 |
with gr.Row():
|
|
|
1 |
+
import torch
|
2 |
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
from torch import autocast
|
|
|
|
|
5 |
from PIL import Image
|
|
|
|
|
6 |
from diffusers import StableDiffusionImg2ImgPipeline
|
7 |
|
8 |
# load the pipeline
|
9 |
device = "cuda"
|
10 |
model_id_or_path = "CompVis/stable-diffusion-v1-4"
|
11 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
12 |
+
model_id_or_path,
|
13 |
revision="fp16",
|
14 |
torch_dtype=torch.float16,
|
15 |
use_auth_token='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'
|
|
|
19 |
pipe = pipe.to(device)
|
20 |
|
21 |
def diffuse(x, param):
|
22 |
+
print('in callback')
|
23 |
+
x = Image.fromarray(np.uint8(x))
|
24 |
+
init_image = x.resize((768, 512))
|
25 |
+
prompt = 'st petersburg logo'
|
26 |
+
if param == 'Эрмитаж':
|
27 |
+
prompt = "st petersburg logo winter palace image on background hermitage vector style"
|
28 |
+
elif param == 'Казанский собор':
|
29 |
+
prompt = "st petersburg logo kazansky sobor image on background"
|
30 |
+
elif param == 'Мосты':
|
31 |
+
prompt = 'st petersburg logo bridges over neva image on background beutiful high quality'
|
32 |
+
|
33 |
+
with autocast("cuda"):
|
34 |
+
images = pipe(prompt=prompt, init_image=init_image, strength=0.7, guidance_scale=7.5).images
|
35 |
+
return [images[0], param]
|
|
|
|
|
|
|
36 |
|
37 |
def flip_image(x, param):
|
38 |
return [np.fliplr(x), 'функция приняла на вход ' + param]
|
39 |
|
40 |
with gr.Blocks() as demo:
|
|
|
41 |
gr.Markdown("Слово 'Санкт-Петербург'")
|
42 |
with gr.Tab("Санкт-Петербург"):
|
43 |
with gr.Row():
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
torch
|
2 |
-
diffusers
|
|
|
1 |
torch
|
2 |
+
git+https://github.com/huggingface/diffusers
|