gaur3009 commited on
Commit
924b685
·
verified ·
1 Parent(s): 21874de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -102
app.py CHANGED
@@ -2,125 +2,54 @@ import gradio as gr
2
  from diffusers import DiffusionPipeline
3
  from PIL import Image
4
  import torch
5
- import os
6
 
7
- # Load Stable Diffusion XL pipeline and LoRA weights
 
 
 
8
  pipe = DiffusionPipeline.from_pretrained(
9
  "stabilityai/stable-diffusion-xl-base-1.0",
10
- torch_dtype=torch.float16,
11
- variant="fp16"
12
- ).to("cuda" if torch.cuda.is_available() else "cpu")
 
13
  pipe.load_lora_weights("artificialguybr/TshirtDesignRedmond-V2")
14
 
15
- # Generate design based on prompts
16
  def infer(color_prompt, phone_type_prompt, design_prompt):
17
  prompt = (
18
  f"A single vertical {color_prompt} colored {phone_type_prompt} back cover featuring a bold {design_prompt} design on the front, hanging on the plain wall. The soft light and shadows, creating a striking contrast against the minimal background, evoking modern sophistication."
19
  )
20
- print("Generating image with prompt:", prompt)
21
  image = pipe(prompt).images[0]
22
  message = "Design generated successfully!"
23
  return image, message
24
 
25
- # Function to save the design
26
  def save_design(image):
27
  file_path = "saved_design.png"
28
  image.save(file_path)
29
  return f"Design saved as {file_path}!"
30
 
31
- # Custom CSS for animations
32
- custom_css = """
33
- body {
34
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
35
- margin: 0;
36
- padding: 0;
37
- overflow: hidden;
38
- }
39
- body::before {
40
- content: "";
41
- position: fixed;
42
- top: 0;
43
- left: 0;
44
- width: 100%;
45
- height: 100%;
46
- background: linear-gradient(-45deg, #ff9a9e, #fad0c4, #fbc2eb, #8fd3f4);
47
- background-size: 400% 400%;
48
- z-index: -1;
49
- animation: gradientShift 15s ease infinite;
50
- }
51
- @keyframes gradientShift {
52
- 0% { background-position: 0% 50%; }
53
- 50% { background-position: 100% 50%; }
54
- 100% { background-position: 0% 50%; }
55
- }
56
- .carousel {
57
- display: flex;
58
- overflow-x: auto;
59
- scroll-behavior: smooth;
60
- }
61
- .carousel .image-container {
62
- display: inline-block;
63
- text-align: center;
64
- margin: 0 10px;
65
- }
66
- .carousel img {
67
- max-height: 200px;
68
- border-radius: 10px;
69
- transition: transform 0.3s;
70
- }
71
- .carousel img:hover {
72
- transform: scale(1.1);
73
- }
74
- .carousel .caption {
75
- margin-top: 5px;
76
- font-size: 14px;
77
- color: #333;
78
- }
79
- """
80
-
81
- with gr.Blocks(css=custom_css) as interface:
82
  gr.Markdown("# **AI Phone Cover Designer**")
83
- gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
84
-
85
- with gr.Tabs():
86
- with gr.Tab("Home"):
87
- gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
88
-
89
- with gr.Tab("Design"):
90
- with gr.Row():
91
- with gr.Column(scale=1):
92
- color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
93
- phone_type_prompt = gr.Textbox(label="Mobile type", placeholder="E.g., iPhone, Samsung")
94
- design_prompt = gr.Textbox(label="Design Details", placeholder="E.g., Bold stripes with geometric patterns")
95
- generate_button = gr.Button("Generate Design")
96
- save_button = gr.Button("Save Design")
97
- with gr.Column(scale=1):
98
- output_image = gr.Image(label="Generated Design")
99
- output_message = gr.Textbox(label="Status", interactive=False)
100
-
101
- generate_button.click(
102
- infer,
103
- inputs=[color_prompt, phone_type_prompt, design_prompt],
104
- outputs=[output_image, output_message],
105
- )
106
- save_button.click(
107
- save_design,
108
- inputs=[output_image],
109
- outputs=output_message,
110
- )
111
-
112
- with gr.Tab("About"):
113
- gr.Markdown("""
114
- ## About AI Phone Cover Maker
115
- The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.
116
- Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
117
-
118
- ### Features:
119
- - Create custom designs using simple prompts.
120
- - Generate designs for various phone models.
121
- - Save your designs for future use.
122
-
123
- Start designing today and bring your creative ideas to life!
124
- """)
125
 
126
- interface.launch(debug=True)
 
2
  from diffusers import DiffusionPipeline
3
  from PIL import Image
4
  import torch
 
5
 
6
+ device = "cuda" if torch.cuda.is_available() else "cpu"
7
+ dtype = torch.float16 if device == "cuda" else torch.float32
8
+ variant = "fp16" if device == "cuda" else None
9
+
10
  pipe = DiffusionPipeline.from_pretrained(
11
  "stabilityai/stable-diffusion-xl-base-1.0",
12
+ torch_dtype=dtype,
13
+ variant=variant
14
+ ).to(device)
15
+
16
  pipe.load_lora_weights("artificialguybr/TshirtDesignRedmond-V2")
17
 
 
18
  def infer(color_prompt, phone_type_prompt, design_prompt):
19
  prompt = (
20
  f"A single vertical {color_prompt} colored {phone_type_prompt} back cover featuring a bold {design_prompt} design on the front, hanging on the plain wall. The soft light and shadows, creating a striking contrast against the minimal background, evoking modern sophistication."
21
  )
 
22
  image = pipe(prompt).images[0]
23
  message = "Design generated successfully!"
24
  return image, message
25
 
 
26
  def save_design(image):
27
  file_path = "saved_design.png"
28
  image.save(file_path)
29
  return f"Design saved as {file_path}!"
30
 
31
+ with gr.Blocks() as interface:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  gr.Markdown("# **AI Phone Cover Designer**")
33
+ with gr.Row():
34
+ with gr.Column(scale=1):
35
+ color_prompt = gr.Textbox(label="Color")
36
+ phone_type_prompt = gr.Textbox(label="Mobile Type")
37
+ design_prompt = gr.Textbox(label="Design Details")
38
+ generate_button = gr.Button("Generate Design")
39
+ save_button = gr.Button("Save Design")
40
+ with gr.Column(scale=1):
41
+ output_image = gr.Image(label="Generated Design")
42
+ output_message = gr.Textbox(label="Status", interactive=False)
43
+
44
+ generate_button.click(
45
+ infer,
46
+ inputs=[color_prompt, phone_type_prompt, design_prompt],
47
+ outputs=[output_image, output_message],
48
+ )
49
+ save_button.click(
50
+ save_design,
51
+ inputs=[output_image],
52
+ outputs=output_message,
53
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ interface.launch(debug=True)