GenAILearniverse commited on
Commit
964fb37
·
verified ·
1 Parent(s): c84db86

Create stivker.py

Browse files
Files changed (1) hide show
  1. stivker.py +115 -0
stivker.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline
2
+ import torch
3
+ import streamlit as st
4
+
5
+
6
+ sdxl_base_model_path = ("../Models/models--stabilityai--stable-diffusion-xl-base-1.0/snapshots"
7
+ "/462165984030d82259a11f4367a4eed129e94a7b")
8
+
9
+ color_book_lora_path = "../Models/Loras/ColoringBookRedmond-ColoringBook-ColoringBookAF (1).safetensors"
10
+ sticker_lora_path = "../Models/Loras/SDXL-StickerSheet-Lora (1).safetensors"
11
+
12
+
13
+ color_book_trigger =", ColoringBookAF, Coloring Book"
14
+ sticker_trigger =", StickerSheet"
15
+
16
+ @st.cache_resource
17
+ def load_pipeline(lora):
18
+
19
+ # pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0",
20
+ # torch_dtype=torch.float16 if device == "cuda" else torch.float32,
21
+ # use_safetensors=True,
22
+ # variant="fp16" if device =="cuda" else None)
23
+ device = "cuda" if torch.cuda.is_available() else "cpu"
24
+ pipe = DiffusionPipeline.from_pretrained(sdxl_base_model_path,
25
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
26
+ use_safetensors=True,
27
+ variant="fp16" if device == "cuda" else None)
28
+ if lora == "Coloring Book":
29
+ pipe.load_lora_weights(color_book_lora_path)
30
+ if lora == "Sticker":
31
+ pipe.load_lora_weights(sticker_lora_path)
32
+
33
+ if device == "cuda":
34
+ pipe.to(device)
35
+ else:
36
+ pipe.enable_model_cpu_offload()
37
+ return pipe
38
+
39
+ def image_generation(pipe, prompt, negative_prompt):
40
+ try:
41
+ image = pipe(
42
+ prompt = prompt,
43
+ negative_prompt = "blurred, ugly, watermark, low resolution" + negative_prompt,
44
+ num_inference_steps= 20,
45
+ guidance_scale=9.0
46
+ ).images[0]
47
+ return image
48
+ except Exception as e:
49
+ st.error(f"Error generating image: {str(e)}")
50
+ return None
51
+
52
+
53
+ import streamlit as st
54
+
55
+ # Define the table as a list of dictionaries with the provided data
56
+ table = [
57
+ {
58
+ "name": "sai-neonpunk",
59
+ "prompt": "neonpunk style . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
60
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured"
61
+ },
62
+ {
63
+ "name": "futuristic-retro cyberpunk",
64
+ "prompt": "retro cyberpunk. 80's inspired, synthwave, neon, vibrant, detailed, retro futurism",
65
+ "negative_prompt": "modern, desaturated, black and white, realism, low contrast"
66
+ },
67
+ {
68
+ "name": "Dark Fantasy",
69
+ "prompt": "Dark Fantasy Art, dark, moody, dark fantasy style",
70
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, bright, sunny"
71
+ },
72
+ {
73
+ "name": "Double Exposure",
74
+ "prompt": "Double Exposure Style, double image ghost effect, image combination, double exposure style",
75
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast"
76
+ },
77
+ {
78
+ "name": "None",
79
+ "prompt": "8K ",
80
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured"
81
+ }
82
+ ]
83
+
84
+ # Convert the list of dictionaries to a dictionary with 'name' as key for easy lookup
85
+ styles_dict = {entry["name"]: entry for entry in table}
86
+
87
+
88
+
89
+
90
+ st.title("Project 13: @GenAILearniverse Sticker Generator")
91
+ prompt = st.text_input("Enter your Prompt", value="A cute Lion")
92
+
93
+ select_lora = st.selectbox("Select your lora", options=["Coloring Book", "Sticker", "None"])
94
+
95
+ # Dropdown for selecting a style
96
+ style_name = st.selectbox("Select a Style", options=list(styles_dict.keys()))
97
+
98
+ # Display the selected style's prompt and negative prompt
99
+ if style_name:
100
+ selected_entry = styles_dict[style_name]
101
+ selected_style_prompt = selected_entry["prompt"];
102
+ selected_style_negative_prompt = selected_entry["negative_prompt"]
103
+ if st.button("Generate Awesome Image"):
104
+ with st.spinner("Generating your awesome image..."):
105
+ pipeline = load_pipeline(select_lora)
106
+ if select_lora == "None":
107
+ image =image_generation(pipeline,prompt + selected_style_prompt, selected_style_negative_prompt)
108
+ else:
109
+ if select_lora == "Coloring Book":
110
+ image = image_generation(pipeline, prompt + selected_style_prompt + color_book_trigger, selected_style_negative_prompt)
111
+ else:
112
+ image = image_generation(pipeline, prompt + selected_style_prompt + sticker_trigger,
113
+ selected_style_negative_prompt)
114
+ if image:
115
+ st.image(image)