GenAILearniverse commited on
Commit
c84db86
·
verified ·
1 Parent(s): 9cb709c

Create app.py

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