HelloAI1 commited on
Commit
72eed8d
·
verified ·
1 Parent(s): 92b7635

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -53
app.py CHANGED
@@ -8,8 +8,8 @@ import os
8
  from PIL import Image
9
  from io import BytesIO
10
 
11
- batch_size=1
12
- batch_count=1
13
 
14
  class Prodia:
15
  def __init__(self, api_key, base=None):
@@ -77,9 +77,6 @@ def image_to_base64(image_path):
77
  return img_str.decode('utf-8') # Convert bytes to string
78
 
79
 
80
-
81
- prodia_client = Prodia(api_key=os.getenv("API_KEY"))
82
-
83
  def flip_text(prompt, negative_prompt, steps, cfg_scale, width, height, seed):
84
  result = prodia_client.generate({
85
  "prompt": prompt,
@@ -97,6 +94,7 @@ def flip_text(prompt, negative_prompt, steps, cfg_scale, width, height, seed):
97
 
98
  return job["imageUrl"]
99
 
 
100
  css = """
101
  #prompt-container .form{
102
  border-top-right-radius: 0;
@@ -123,53 +121,19 @@ css = """
123
  }
124
  """
125
 
 
 
 
 
 
 
126
  with gr.Blocks(css=css) as demo:
127
  gr.HTML(
128
  """
129
  <div style="text-align: center; margin: 0 auto;">
130
- <div
131
- style="
132
- display: inline-flex;
133
- align-items: center;
134
- gap: 0.8rem;
135
- font-size: 1.75rem;
136
- "
137
- >
138
- <svg
139
- width="0.65em"
140
- height="0.65em"
141
- viewBox="0 0 115 115"
142
- fill="none"
143
- xmlns="http://www.w3.org/2000/svg"
144
- >
145
- <rect width="23" height="23" fill="white"></rect>
146
- <rect y="69" width="23" height="23" fill="white"></rect>
147
- <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
148
- <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
149
- <rect x="69" width="23" height="23" fill="black"></rect>
150
- <rect x="69" y="69" width="23" height="23" fill="black"></rect>
151
- <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
152
- <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
153
- <rect x="115" y="46" width="23" height="23" fill="white"></rect>
154
- <rect x="115" y="115" width="23" height="23" fill="white"></rect>
155
- <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
156
- <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
157
- <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
158
- <rect x="92" y="69" width="23" height="23" fill="white"></rect>
159
- <rect x="69" y="46" width="23" height="23" fill="white"></rect>
160
- <rect x="69" y="115" width="23" height="23" fill="white"></rect>
161
- <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
162
- <rect x="46" y="46" width="23" height="23" fill="black"></rect>
163
- <rect x="46" y="115" width="23" height="23" fill="black"></rect>
164
- <rect x="46" y="69" width="23" height="23" fill="black"></rect>
165
- <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
166
- <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
167
- <rect x="23" y="69" width="23" height="23" fill="black"></rect>
168
- </svg>
169
- <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
170
- Disney AI Pixar Poster Generator
171
- </h1>
172
- </div>
173
  </div>
174
  """)
175
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
@@ -179,7 +143,7 @@ with gr.Blocks(css=css) as demo:
179
  text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
180
  with gr.Row():
181
  with gr.Column(scale=1):
182
- image_output = gr.Image(elem_id="gallery")
183
  with gr.Row():
184
  with gr.Accordion("Additional inputs", open=False):
185
  with gr.Column(scale=1):
@@ -187,10 +151,10 @@ with gr.Blocks(css=css) as demo:
187
  height = gr.Slider(label="↕️ Height", minimum=512, maximum=1024, value=1024, step=8)
188
  negative_prompt = gr.Textbox(label="Negative Prompt", value="blurry, black and white, (deformed head, eyes, ears, mouth)", placeholder="What you don't want to see in the image", show_label=True, lines=1, elem_id="negative-prompt-text-input")
189
  steps = gr.Slider(label="Sampling Steps (higher value means more details)", minimum=1, maximum=30, value=25, step=1)
190
- cfg_scale = gr.Slider(label="CFG Scale (higher value means more closely following the prompt)", minimum=1, maximum=20, value=7, step=1)
191
- seed = gr.Number(label="Seed (use -1 for random)", value=-1)
192
 
193
- text_button.click(flip_text, inputs=[prompt, negative_prompt, steps, cfg_scale, width, height, seed], outputs=image_output)
194
- text_button.click(lambda: gr.update(label="Your Image will be ready in few seconds"), outputs=text_button)
195
 
196
  demo.queue(concurrency_count=16, max_size=20, api_open=False).launch(max_threads=64)
 
8
  from PIL import Image
9
  from io import BytesIO
10
 
11
+ batch_size = 1
12
+ batch_count = 1
13
 
14
  class Prodia:
15
  def __init__(self, api_key, base=None):
 
77
  return img_str.decode('utf-8') # Convert bytes to string
78
 
79
 
 
 
 
80
  def flip_text(prompt, negative_prompt, steps, cfg_scale, width, height, seed):
81
  result = prodia_client.generate({
82
  "prompt": prompt,
 
94
 
95
  return job["imageUrl"]
96
 
97
+
98
  css = """
99
  #prompt-container .form{
100
  border-top-right-radius: 0;
 
121
  }
122
  """
123
 
124
+ # Load the default image
125
+ default_image_path = "image (6).png"
126
+ default_image = Image.open(default_image_path)
127
+
128
+ prodia_client = Prodia(api_key=os.getenv("API_KEY"))
129
+
130
  with gr.Blocks(css=css) as demo:
131
  gr.HTML(
132
  """
133
  <div style="text-align: center; margin: 0 auto;">
134
+ <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px">
135
+ Disney AI Pixar Poster Generator
136
+ </h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  </div>
138
  """)
139
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
 
143
  text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
144
  with gr.Row():
145
  with gr.Column(scale=1):
146
+ image_output = gr.Image(value=default_image, elem_id="gallery") # Set the default image here
147
  with gr.Row():
148
  with gr.Accordion("Additional inputs", open=False):
149
  with gr.Column(scale=1):
 
151
  height = gr.Slider(label="↕️ Height", minimum=512, maximum=1024, value=1024, step=8)
152
  negative_prompt = gr.Textbox(label="Negative Prompt", value="blurry, black and white, (deformed head, eyes, ears, mouth)", placeholder="What you don't want to see in the image", show_label=True, lines=1, elem_id="negative-prompt-text-input")
153
  steps = gr.Slider(label="Sampling Steps (higher value means more details)", minimum=1, maximum=30, value=25, step=1)
154
+ cfg_scale = gr.Slider(label="CFG Scale (higher value means more creative freedom)", minimum=1, maximum=20, value=7, step=1)
155
+ seed = gr.Number(label="Seed", value=-1)
156
 
157
+ text_button.click(lambda: gr.update(label="Your Image will be ready in few seconds"), outputs=text_button)
158
+ text_button.click(flip_text, inputs=[prompt, negative_prompt, steps, cfg_scale, width, height, seed], outputs=image_output)
159
 
160
  demo.queue(concurrency_count=16, max_size=20, api_open=False).launch(max_threads=64)