Nifemi Alpine Durin commited on
Commit
4ed1730
·
1 Parent(s): 7a84f3a
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -8,13 +8,18 @@ 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
 
 
8
  APP_ENV = os.environ.get("APP_ENV", None)
9
 
10
 
11
+ def image_to_base64(input_file):
12
+ if input_file is None:
13
  return None
14
 
15
+ file_bytes = None
16
+ # Check if the input is a string (file path)
17
+ if isinstance(input_file, str):
18
+ with open(input_file, "rb") as file:
19
+ file_bytes = file.read()
20
+ else:
21
+ # Handle file-like object (_TemporaryFileWrapper)
22
+ file_bytes = input_file.read()
23
 
24
  return base64.b64encode(file_bytes).decode()
25