test
Browse files
app.py
CHANGED
|
@@ -1,7 +1,65 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
model_id_or_path,
|
| 16 |
+
revision="fp16",
|
| 17 |
+
torch_dtype=torch.float16,
|
| 18 |
+
use_auth_token='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'
|
| 19 |
+
)
|
| 20 |
+
# or download via git clone https://huggingface.co/CompVis/stable-diffusion-v1-4
|
| 21 |
+
# and pass `model_id_or_path="./stable-diffusion-v1-4"` without having to use `use_auth_token=True`.
|
| 22 |
+
pipe = pipe.to(device)
|
| 23 |
+
|
| 24 |
+
def diffuse(x, param):
|
| 25 |
+
print('in callback')
|
| 26 |
+
x = Image.fromarray(np.uint8(x))
|
| 27 |
+
init_image = x.resize((768, 512))
|
| 28 |
+
prompt = 'st petersburg logo'
|
| 29 |
+
if param == 'Эрмитаж':
|
| 30 |
+
prompt = "st petersburg logo winter palace image on background hermitage vector style"
|
| 31 |
+
elif param == 'Казанский собор':
|
| 32 |
+
prompt = "st petersburg logo kazansky sobor image on background"
|
| 33 |
+
elif param == 'Мосты':
|
| 34 |
+
prompt = 'st petersburg logo bridges over neva image on background beutiful high quality'
|
| 35 |
+
|
| 36 |
+
with autocast("cuda"):
|
| 37 |
+
images = pipe(prompt=prompt, init_image=init_image, strength=0.7, guidance_scale=7.5).images
|
| 38 |
+
return [images[0], param]
|
| 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():
|
| 51 |
+
image_input = gr.Image()
|
| 52 |
+
param_input = gr.Radio(["Эрмитаж", "Мосты", "Казанский собор"], label='Что для тебя Санкт-Петербург?')
|
| 53 |
+
image_output = gr.Image()
|
| 54 |
+
param_out = gr.Markdown()
|
| 55 |
+
image_button = gr.Button("GET IMAGE")
|
| 56 |
+
|
| 57 |
+
image_button.click(diffuse, [image_input, param_input], [image_output, param_out])
|
| 58 |
+
|
| 59 |
+
demo.launch()
|
| 60 |
+
|
| 61 |
+
#def greet(name):
|
| 62 |
+
# return "Hello " + name + "!!"
|
| 63 |
+
|
| 64 |
+
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 65 |
+
#iface.launch()
|