Nifemi Alpine Durin commited on
Commit
c6f24f8
·
1 Parent(s): cc2aaf9

upgrade ui

Browse files
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- import requests
3
  from dotenv import load_dotenv
4
  import os, datetime
5
 
@@ -7,8 +7,20 @@ load_dotenv()
7
  API_URL = os.environ.get("API_URL", "http://0.0.0.0:8021")
8
  APP_ENV = os.environ.get("APP_ENV", None)
9
 
 
 
 
 
 
 
 
 
 
10
  # Assuming the API returns an image URL in the response
11
- def generate_image(brand_name, primary_color, secondary_color, description, target_audience, font, logo_url, heading_text, sub_heading_text, image_dimension, custom_graphic_prompt):
 
 
 
12
  # Define your payload/data to send to the image generation API
13
  data = {
14
  "brand_name": brand_name,
@@ -19,9 +31,9 @@ def generate_image(brand_name, primary_color, secondary_color, description, targ
19
  "font": font,
20
  "heading_text": heading_text or "",
21
  "sub_heading_text": sub_heading_text or "",
22
- "logo_url": logo_url,
23
  "user_prompt": custom_graphic_prompt,
24
- "image_dimension": image_dimension
25
  }
26
 
27
  # Make the API call
@@ -49,17 +61,17 @@ iface = gr.Interface(
49
  gr.components.Textbox(placeholder="Brief description of your brand and design guidelines", label="Description", lines=2),
50
  gr.components.Textbox(placeholder="Your Brand's target audience", label="Target Audience"),
51
  gr.components.Textbox(placeholder="Google Font Label i.e Rubik", label="Font"),
52
- gr.components.Textbox(placeholder="Url of your brand logo (not required)", label="Logo Url"),
53
  gr.components.Textbox(placeholder="Heading text (not required)", label="Heading Text"),
54
  gr.components.Textbox(placeholder="Paragraph text (not required)", label="Sub Heading Text"),
55
  gr.components.Dropdown(
56
  choices=[
57
- ("Select Dimension", "750x1334"),
58
  ("Mobile Portrait (750x1334)", "750x1334"),
59
  ("Square (2048x2048)", "2048x2048")
60
  ],
61
  value="750x1334",
62
- label="Image Dimension"
63
  ),
64
  gr.components.Textbox(lines=4, placeholder="Enter your custom dall-e 2-3 image prompt here (not required)", value="", label="Custom Graphic Prompt")
65
  ],
 
1
  import gradio as gr
2
+ import requests, base64, io
3
  from dotenv import load_dotenv
4
  import os, datetime
5
 
 
7
  API_URL = os.environ.get("API_URL", "http://0.0.0.0:8021")
8
  APP_ENV = os.environ.get("APP_ENV", None)
9
 
10
+
11
+ def image_to_base64(image):
12
+ if image is None:
13
+ return None
14
+ buffered = io.BytesIO()
15
+ image.save(buffered, format="PNG")
16
+ return base64.b64encode(buffered.getvalue()).decode()
17
+
18
+
19
  # Assuming the API returns an image URL in the response
20
+ def generate_image(brand_name, primary_color, secondary_color, description, target_audience, font, logo_image, heading_text, sub_heading_text, image_layout, custom_graphic_prompt):
21
+
22
+ logo_base64 = image_to_base64(logo_image)
23
+
24
  # Define your payload/data to send to the image generation API
25
  data = {
26
  "brand_name": brand_name,
 
31
  "font": font,
32
  "heading_text": heading_text or "",
33
  "sub_heading_text": sub_heading_text or "",
34
+ "logo_url": logo_base64,
35
  "user_prompt": custom_graphic_prompt,
36
+ "image_dimension": image_layout
37
  }
38
 
39
  # Make the API call
 
61
  gr.components.Textbox(placeholder="Brief description of your brand and design guidelines", label="Description", lines=2),
62
  gr.components.Textbox(placeholder="Your Brand's target audience", label="Target Audience"),
63
  gr.components.Textbox(placeholder="Google Font Label i.e Rubik", label="Font"),
64
+ gr.components.Image(tool="select", type="pil", label="Logo Image"), # Image upload for logo
65
  gr.components.Textbox(placeholder="Heading text (not required)", label="Heading Text"),
66
  gr.components.Textbox(placeholder="Paragraph text (not required)", label="Sub Heading Text"),
67
  gr.components.Dropdown(
68
  choices=[
69
+ ("Select Layout", "750x1334"),
70
  ("Mobile Portrait (750x1334)", "750x1334"),
71
  ("Square (2048x2048)", "2048x2048")
72
  ],
73
  value="750x1334",
74
+ label="Image Layout"
75
  ),
76
  gr.components.Textbox(lines=4, placeholder="Enter your custom dall-e 2-3 image prompt here (not required)", value="", label="Custom Graphic Prompt")
77
  ],
images/temp_image_20231208120927.png DELETED
Binary file (449 kB)
 
images/temp_image_20231208122352.png DELETED
Binary file (989 kB)