JoPmt commited on
Commit
cd7c888
1 Parent(s): 57ff858

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -0
app.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DPMSolverMultistepScheduler
2
+ import gradio as gr
3
+ from PIL import Image
4
+ import cv2
5
+ import qrcode
6
+ import numpy as np
7
+ from transformers import pipeline
8
+ import PIL.Image
9
+ from diffusers.utils import load_image
10
+ from accelerate import Accelerator
11
+ from diffusers import StableDiffusionPipeline
12
+ import torch
13
+ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
14
+
15
+ accelerator = Accelerator(cpu=True)
16
+ models =[
17
+ "runwayml/stable-diffusion-v1-5",
18
+ "prompthero/openjourney-v4",
19
+ "CompVis/stable-diffusion-v1-4",
20
+ "stabilityai/stable-diffusion-2-1",
21
+ "stablediffusionapi/disney-pixal-cartoon",
22
+ "stablediffusionapi/edge-of-realism",
23
+ "MirageML/fantasy-scene",
24
+ "wavymulder/lomo-diffusion",
25
+ "sd-dreambooth-library/fashion",
26
+ "DucHaiten/DucHaitenDreamWorld",
27
+ "VegaKH/Ultraskin",
28
+ "kandinsky-community/kandinsky-2-1",
29
+ "MirageML/lowpoly-cyberpunk",
30
+ "thehive/everyjourney-sdxl-0.9-finetuned",
31
+ "plasmo/woolitize-768sd1-5",
32
+ "plasmo/food-crit",
33
+ "johnslegers/epic-diffusion-v1.1",
34
+ "Fictiverse/ElRisitas",
35
+ "robotjung/SemiRealMix",
36
+ "herpritts/FFXIV-Style",
37
+ "prompthero/linkedin-diffusion",
38
+ "RayHell/popupBook-diffusion",
39
+ "MirageML/lowpoly-world",
40
+ "deadman44/SD_Photoreal_Merged_Models",
41
+ "Conflictx/CGI_Animation",
42
+ "johnslegers/epic-diffusion",
43
+ "tilake/China-Chic-illustration",
44
+ "wavymulder/modelshoot",
45
+ "prompthero/openjourney-lora",
46
+ "Fictiverse/Stable_Diffusion_VoxelArt_Model",
47
+ "darkstorm2150/Protogen_v2.2_Official_Release",
48
+ "hassanblend/HassanBlend1.5.1.2",
49
+ "hassanblend/hassanblend1.4",
50
+ "nitrosocke/redshift-diffusion",
51
+ "prompthero/openjourney-v2",
52
+ "nitrosocke/Arcane-Diffusion",
53
+ "Lykon/DreamShaper",
54
+ "wavymulder/Analog-Diffusion",
55
+ "nitrosocke/mo-di-diffusion",
56
+ "dreamlike-art/dreamlike-diffusion-1.0",
57
+ "dreamlike-art/dreamlike-photoreal-2.0",
58
+ "digiplay/RealismEngine_v1",
59
+ "digiplay/AIGEN_v1.4_diffusers",
60
+ "stablediffusionapi/dreamshaper-v6",
61
+ "JackAnon/GorynichMix",
62
+ "p1atdev/liminal-space-diffusion",
63
+ "nadanainone/gigaschizonegs",
64
+ "darkVOYAGE/dvMJv4",
65
+ "lckidwell/album-cover-style",
66
+ "axolotron/ice-cream-animals",
67
+ "perion/ai-avatar",
68
+ "digiplay/GhostMix",
69
+ "ThePioneer/MISA",
70
+ "TheLastBen/froggy-style-v21-768",
71
+ "FloydianSound/Nixeu_Diffusion_v1-5",
72
+ "kakaobrain/karlo-v1-alpha-image-variations",
73
+ "digiplay/PotoPhotoRealism_v1",
74
+ "ConsistentFactor/Aurora-By_Consistent_Factor",
75
+ "rim0/quadruped_mechas",
76
+ "Akumetsu971/SD_Samurai_Anime_Model",
77
+ "Bojaxxx/Fantastic-Mr-Fox-Diffusion",
78
+ "sd-dreambooth-library/original-character-cyclps",
79
+ "AIArtsChannel/steampunk-diffusion",
80
+ ]
81
+
82
+ controlnet = accelerator.prepare(ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float32))
83
+ generator = torch.Generator(device="cpu").manual_seed(1)
84
+ def plex(qr_code_value, text, neg_text, modil, one, two, three):
85
+ apol=[]
86
+ modal=""+modil+""
87
+ pipe = accelerator.prepare(StableDiffusionControlNetPipeline.from_pretrained(modal, controlnet=controlnet, torch_dtype=torch.float32, use_safetensors=False, safety_checker=None))
88
+ pipe.scheduler = accelerator.prepare(DPMSolverMultistepScheduler.from_config(pipe.scheduler.config))
89
+ pipe = pipe.to("cpu")
90
+ negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality"
91
+ prompt = text
92
+ qr_code = qrcode.make(qr_code_value).resize((512, 512))
93
+ rmage = load_image(qr_code)
94
+ original = rmage.convert("RGB")
95
+ original.thumbnail((512, 512))
96
+ cannyimage = load_image(original).resize((512,512))
97
+ cannyimage = np.array(cannyimage)
98
+ low_threshold = 100
99
+ high_threshold = 200
100
+ cannyimage = cv2.Canny(cannyimage, low_threshold, high_threshold)
101
+ cannyimage = cannyimage[:, :, None]
102
+ cannyimage = np.concatenate([cannyimage, cannyimage, cannyimage], axis=2)
103
+ cannyimage = Image.fromarray(cannyimage)
104
+ images = [cannyimage]
105
+
106
+ image = pipe(
107
+ [prompt]*2,
108
+ images,
109
+ num_inference_steps=one,
110
+ generator=generator,
111
+ strength=two
112
+ negative_prompt=[neg_prompt]*2,
113
+ controlnet_conditioning_scale=three,
114
+ )
115
+ for i, imge in enumerate(imoge["images"]):
116
+ apol.append(imge)
117
+ apol.append(original)
118
+ apol.append(cannyimage)
119
+ return apol
120
+
121
+ iface = gr.Interface(fn=plex, inputs=[gr.Textbox(label="QR Code URL"),gr.Textbox(label="prompt"),gr.Textbox(label="neg prompt"),gr.Dopdown(choices=models, label="some sd models", value=models[0]), gr.Slider(label="num inference steps", minimum=1, step=1, maximum=5, value=5), gr.Slider(label="prompt strength", minimum=0.1, step=0.1, maximum=1, value=0.2), gr.Slider(label="controlnet scale", minimum=0.1, step=0.1, maximum=1, value=0.8)], outputs=gr.Gallery(label="out", columns=1))
122
+ iface.queue(max=1)
123
+ iface.launch()