Nifemi Alpine Durin commited on
Commit
2e415e8
·
1 Parent(s): c6f24f8
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -2,18 +2,21 @@ import gradio as gr
2
  import requests, base64, io
3
  from dotenv import load_dotenv
4
  import os, datetime
5
-
6
  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
 
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
@@ -61,7 +64,7 @@ iface = gr.Interface(
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(
 
2
  import requests, base64, io
3
  from dotenv import load_dotenv
4
  import os, datetime
5
+ from PIL import Image
6
  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
 
11
+ def image_to_base64(file_path):
12
+ if file_path is None:
13
  return None
14
+
15
+ # Read the file content from the file path
16
+ with open(file_path, "rb") as file:
17
+ file_bytes = file.read()
18
+
19
+ return base64.b64encode(file_bytes).decode()
20
 
21
 
22
  # Assuming the API returns an image URL in the response
 
64
  gr.components.Textbox(placeholder="Brief description of your brand and design guidelines", label="Description", lines=2),
65
  gr.components.Textbox(placeholder="Your Brand's target audience", label="Target Audience"),
66
  gr.components.Textbox(placeholder="Google Font Label i.e Rubik", label="Font"),
67
+ gr.components.File(label="Logo Image", scale=2, file_types=["jpg", "jpeg", "png", "gif", "bmp"]),
68
  gr.components.Textbox(placeholder="Heading text (not required)", label="Heading Text"),
69
  gr.components.Textbox(placeholder="Paragraph text (not required)", label="Sub Heading Text"),
70
  gr.components.Dropdown(