kraxenia commited on
Commit
75bed3a
·
verified ·
1 Parent(s): 52e1bdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -11,7 +11,13 @@ import base64
11
  hf_token = os.environ.get("HF_TOKEN_API_DEMO") # we get it from a secret env variable, such that it's private
12
  auth_headers = {"api_token": hf_token}
13
 
14
-
 
 
 
 
 
 
15
  def download_image(url):
16
  response = requests.get(url)
17
  img_bytes = BytesIO(response.content)
@@ -35,7 +41,7 @@ def predict(dict, prompt):
35
 
36
  init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
37
 
38
- image_base64_file = convert_mask_image_to_base64_string(init_image)
39
 
40
  gen_img = api_call(image_base64_file, mask_base64_file, prompt)
41
 
 
11
  hf_token = os.environ.get("HF_TOKEN_API_DEMO") # we get it from a secret env variable, such that it's private
12
  auth_headers = {"api_token": hf_token}
13
 
14
+ def convert_image_to_base64_string(img):
15
+ buffer = io.BytesIO()
16
+ img.save(buffer, format="PNG") # You can choose the format (e.g., "JPEG", "PNG")
17
+ # Encode the buffer in base64
18
+ image_base64_string = base64.b64encode(buffer.getvalue()).decode('utf-8')
19
+ return f",{image_base64_string}"
20
+
21
  def download_image(url):
22
  response = requests.get(url)
23
  img_bytes = BytesIO(response.content)
 
41
 
42
  init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
43
 
44
+ image_base64_file = convert_image_to_base64_string(init_image)
45
 
46
  gen_img = api_call(image_base64_file, mask_base64_file, prompt)
47