Mohit0199 commited on
Commit
75373d5
·
verified ·
1 Parent(s): bfabe04

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline
2
+ import torch
3
+ import streamlit as st
4
+
5
+
6
+ @st.cache_resource
7
+ def load_pipeline():
8
+
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0",
11
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
12
+ use_safetensors=True,
13
+ variant="fp16" if device == "cuda" else None)
14
+ return pipe
15
+
16
+
17
+ def image_generation(pipe, prompt, negative_prompt):
18
+ try:
19
+ image = pipe(
20
+ prompt = prompt,
21
+ negative_prompt = "blurred, ugly, watermark, low resolution" + negative_prompt,
22
+ num_inference_steps= 20,
23
+ guidance_scale=9.0
24
+ ).images[0]
25
+ return image
26
+ except Exception as e:
27
+ st.error(f"Error generating image: {str(e)}")
28
+ return None
29
+
30
+
31
+ import streamlit as st
32
+
33
+ # Define the table as a list of dictionaries with the provided data
34
+ table = [
35
+ {
36
+ "name": "sai-neonpunk",
37
+ "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",
38
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured"
39
+ },
40
+ {
41
+ "name": "futuristic-retro cyberpunk",
42
+ "prompt": "retro cyberpunk. 80's inspired, synthwave, neon, vibrant, detailed, retro futurism",
43
+ "negative_prompt": "modern, desaturated, black and white, realism, low contrast"
44
+ },
45
+ {
46
+ "name": "Dark Fantasy",
47
+ "prompt": "Dark Fantasy Art, dark, moody, dark fantasy style",
48
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, bright, sunny"
49
+ },
50
+ {
51
+ "name": "Double Exposure",
52
+ "prompt": "Double Exposure Style, double image ghost effect, image combination, double exposure style",
53
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast"
54
+ }
55
+ ]
56
+
57
+ # Convert the list of dictionaries to a dictionary with 'name' as key for easy lookup
58
+ styles_dict = {entry["name"]: entry for entry in table}
59
+
60
+ st.title("Image Generation")
61
+ prompt = st.text_input("Enter your Prompt", value="A futuristic superhero cat")
62
+
63
+ pipeline = load_pipeline()
64
+ style_name = st.selectbox("Select a Style", options=list(styles_dict.keys()))
65
+
66
+ # Display the selected style's prompt and negative prompt
67
+ if style_name:
68
+ selected_entry = styles_dict[style_name]
69
+ selected_style_prompt = selected_entry["prompt"];
70
+ selected_style_negative_prompt = selected_entry["negative_prompt"]
71
+
72
+ if st.button("Generate Awesome Image"):
73
+ with st.spinner("Generating your awesome image..."):
74
+ image =image_generation(pipeline,prompt + selected_style_prompt, selected_style_negative_prompt)
75
+ if image:
76
+ st.image(image)