Yao211 commited on
Commit
faa89fc
·
verified ·
1 Parent(s): fa0c6a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -45
app.py CHANGED
@@ -13,6 +13,10 @@ COMPANY_NAME = "Miragic"
13
  COMPANY_URL = "https://www.miragic.ai"
14
  CONTACT_EMAIL = "info@miragic.ai"
15
 
 
 
 
 
16
  def generate_image_via_api(prompt, model, width, height, seed, image_url, enhance, safe):
17
  """
18
  Call the Flask API to generate an image
@@ -42,7 +46,7 @@ def generate_image_via_api(prompt, model, width, height, seed, image_url, enhanc
42
  response = requests.post(
43
  f"{MIRAGIC_API_URL}/generate_image",
44
  json=data,
45
- timeout=300 # Increased timeout for image generation
46
  )
47
 
48
  if response.status_code == 200:
@@ -69,18 +73,16 @@ def generate_image_via_api(prompt, model, width, height, seed, image_url, enhanc
69
  raise gr.Error(f"Unexpected Error: {str(e)}")
70
 
71
  def get_available_models():
72
- """
73
- Get available models from the Flask API
74
- """
75
  try:
76
  response = requests.get(f"{MIRAGIC_API_URL}/available_models", timeout=10)
77
  if response.status_code == 200:
78
  result = response.json()
79
  if result["status"] == "success":
80
  return result["models"]
81
- return ["flux", "kontext", "dreamshaper", "realistic", "anime"]
82
  except:
83
- return ["flux", "kontext", "dreamshaper", "realistic", "anime"]
84
 
85
  def handle_like_action():
86
  """Handle like button click"""
@@ -122,6 +124,10 @@ def create_instructions_html():
122
  def get_css_styles():
123
  """Get CSS styles for the interface"""
124
  return """
 
 
 
 
125
  footer {visibility: hidden}
126
  .banner {
127
  background-color: #f8f9fa;
@@ -173,48 +179,32 @@ footer {visibility: hidden}
173
  background: linear-gradient(45deg, #ff416c, #ff4b2b);
174
  border: none;
175
  padding: 12px 25px;
176
- font-size: 16px;
177
- font-weight: bold;
178
- color: white;
179
- border-radius: 8px;
180
- text-decoration: none;
181
- display: inline-block;
182
- transition: all 0.3s ease;
183
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
184
  }
185
  .signup-button:hover {
186
- transform: translateY(-2px);
187
- box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
188
- }
189
- #col-container {
190
- max-width: 1400px;
191
- margin: 0 auto;
192
  }
193
  .step-column {
194
  padding: 20px;
195
  border-radius: 8px;
196
- box-shadow: var(--card-shadow);
197
  margin: 10px;
198
  }
199
  .step-title {
200
- color: var(--primary-color);
201
  text-align: center;
202
  margin-bottom: 15px;
203
  }
204
  .image-preview {
205
  border-radius: 8px;
206
  overflow: hidden;
207
- box-shadow: var(--card-shadow);
208
- }
209
- .result-section {
210
- background-color: white;
211
- padding: 20px;
212
- border-radius: 8px;
213
- box-shadow: var(--card-shadow);
214
- }
215
- .footer {
216
- margin-top: 30px;
217
- text-align: center;
218
  }
219
  .like-button {
220
  background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
@@ -252,12 +242,12 @@ footer {visibility: hidden}
252
  """
253
 
254
  # Create the Gradio interface
255
- with gr.Blocks(css=get_css_styles(), title=f"{COMPANY_NAME} AI Image Generator", theme=gr.themes.Ocean()) as demo:
256
  with gr.Row():
257
- with gr.Column(0.7):
258
  gr.Markdown(f"""
259
  <div style="display: flex; align-items: center;">
260
- <img src="https://avatars.githubusercontent.com/u/211682198?s=200&v=4" style="width: 80px; margin-right: 20px;"/>
261
  <div>
262
  <h1 style="margin-bottom: 0;">{COMPANY_NAME} AI Image Generator 🎨</h1>
263
  <p style="margin-top: 0; color: #636e72;">Create stunning AI-generated images with text prompts</p>
@@ -266,16 +256,16 @@ with gr.Blocks(css=get_css_styles(), title=f"{COMPANY_NAME} AI Image Generator",
266
  """)
267
 
268
  gr.HTML(create_instructions_html())
269
- with gr.Column(0.3):
270
  gr.Markdown(f"""
271
- <div style="display: flex; align-items: center;">
272
- <img src="https://miragic.ai/products/qrcode-vto.png" style="width: 450px; margin-left: 100px;"/>
273
  </div>
274
  """)
275
 
276
- with gr.Row(elem_id="col-container"):
277
  # Step 1: Prompt and Settings
278
- with gr.Column(elem_classes="step-column"):
279
  gr.HTML("""
280
  <div class="step-title">
281
  <span style="font-size: 24px;">1. Enter Prompt & Settings</span><br>
@@ -340,7 +330,7 @@ with gr.Blocks(css=get_css_styles(), title=f"{COMPANY_NAME} AI Image Generator",
340
  )
341
 
342
  # Step 2: Results
343
- with gr.Column(elem_classes="step-column"):
344
  gr.HTML("""
345
  <div class="step-title">
346
  <span style="font-size: 24px;">2. Generated Image</span><br>
@@ -350,7 +340,6 @@ with gr.Blocks(css=get_css_styles(), title=f"{COMPANY_NAME} AI Image Generator",
350
  result_img = gr.Image(
351
  label="Generated Image",
352
  interactive=False,
353
- elem_classes="image-preview",
354
  height=400
355
  )
356
 
@@ -400,8 +389,7 @@ with gr.Blocks(css=get_css_styles(), title=f"{COMPANY_NAME} AI Image Generator",
400
  generate_btn.click(
401
  fn=generate_image_via_api,
402
  inputs=[prompt, model, width, height, seed, image_url, enhance, safe],
403
- outputs=[result_img, like_button],
404
- api_name="generate_image"
405
  )
406
 
407
  like_button.click(
 
13
  COMPANY_URL = "https://www.miragic.ai"
14
  CONTACT_EMAIL = "info@miragic.ai"
15
 
16
+ # Use absolute URLs for images
17
+ COMPANY_LOGO_URL = "https://avatars.githubusercontent.com/u/211682198?s=200&v=4"
18
+ QR_CODE_URL = "https://miragic.ai/products/qrcode-vto.png"
19
+
20
  def generate_image_via_api(prompt, model, width, height, seed, image_url, enhance, safe):
21
  """
22
  Call the Flask API to generate an image
 
46
  response = requests.post(
47
  f"{MIRAGIC_API_URL}/generate_image",
48
  json=data,
49
+ timeout=300
50
  )
51
 
52
  if response.status_code == 200:
 
73
  raise gr.Error(f"Unexpected Error: {str(e)}")
74
 
75
  def get_available_models():
76
+ """Get available models from the Flask API"""
 
 
77
  try:
78
  response = requests.get(f"{MIRAGIC_API_URL}/available_models", timeout=10)
79
  if response.status_code == 200:
80
  result = response.json()
81
  if result["status"] == "success":
82
  return result["models"]
83
+ return ["flux", "kontext", "dreamshaper", "realistic", "anime", "turbo"]
84
  except:
85
+ return ["flux", "kontext", "dreamshaper", "realistic", "anime", "turbo"]
86
 
87
  def handle_like_action():
88
  """Handle like button click"""
 
124
  def get_css_styles():
125
  """Get CSS styles for the interface"""
126
  return """
127
+ .gradio-container {
128
+ max-width: 1400px !important;
129
+ margin: 0 auto;
130
+ }
131
  footer {visibility: hidden}
132
  .banner {
133
  background-color: #f8f9fa;
 
179
  background: linear-gradient(45deg, #ff416c, #ff4b2b);
180
  border: none;
181
  padding: 12px 25px;
182
+ font-size: 16px;
183
+ font-weight: bold;
184
+ color: white;
185
+ border-radius: 8px;
186
+ text-decoration: none;
187
+ display: inline-block;
188
+ transition: all 0.3s ease;
189
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
190
  }
191
  .signup-button:hover {
192
+ transform: translateY(-2px);
193
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
 
 
 
 
194
  }
195
  .step-column {
196
  padding: 20px;
197
  border-radius: 8px;
 
198
  margin: 10px;
199
  }
200
  .step-title {
201
+ color: #007bff;
202
  text-align: center;
203
  margin-bottom: 15px;
204
  }
205
  .image-preview {
206
  border-radius: 8px;
207
  overflow: hidden;
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
  .like-button {
210
  background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
 
242
  """
243
 
244
  # Create the Gradio interface
245
+ with gr.Blocks(css=get_css_styles(), title=f"{COMPANY_NAME} AI Image Generator") as demo:
246
  with gr.Row():
247
+ with gr.Column(scale=7):
248
  gr.Markdown(f"""
249
  <div style="display: flex; align-items: center;">
250
+ <img src="{COMPANY_LOGO_URL}" style="width: 80px; height: 80px; margin-right: 20px; border-radius: 8px;"/>
251
  <div>
252
  <h1 style="margin-bottom: 0;">{COMPANY_NAME} AI Image Generator 🎨</h1>
253
  <p style="margin-top: 0; color: #636e72;">Create stunning AI-generated images with text prompts</p>
 
256
  """)
257
 
258
  gr.HTML(create_instructions_html())
259
+ with gr.Column(scale=3):
260
  gr.Markdown(f"""
261
+ <div style="display: flex; justify-content: center;">
262
+ <img src="{QR_CODE_URL}" style="width: 200px; height: 200px; border-radius: 8px;"/>
263
  </div>
264
  """)
265
 
266
+ with gr.Row():
267
  # Step 1: Prompt and Settings
268
+ with gr.Column():
269
  gr.HTML("""
270
  <div class="step-title">
271
  <span style="font-size: 24px;">1. Enter Prompt & Settings</span><br>
 
330
  )
331
 
332
  # Step 2: Results
333
+ with gr.Column():
334
  gr.HTML("""
335
  <div class="step-title">
336
  <span style="font-size: 24px;">2. Generated Image</span><br>
 
340
  result_img = gr.Image(
341
  label="Generated Image",
342
  interactive=False,
 
343
  height=400
344
  )
345
 
 
389
  generate_btn.click(
390
  fn=generate_image_via_api,
391
  inputs=[prompt, model, width, height, seed, image_url, enhance, safe],
392
+ outputs=[result_img, like_button]
 
393
  )
394
 
395
  like_button.click(