giorgio-caparvi commited on
Commit
5b474cb
·
1 Parent(s): eb4abb8

passing image in json

Browse files
Files changed (1) hide show
  1. api/app.py +7 -3
api/app.py CHANGED
@@ -6,6 +6,8 @@ import io
6
  from model.src.utils.arg_parser import eval_parse_args # Nuovo import corretto
7
  import sys
8
  from PIL import Image
 
 
9
 
10
  from model.src import eval
11
 
@@ -29,13 +31,15 @@ def generate_design():
29
  print("### JSON ricevuto:", json_data_from_req) # Stampa per il debug
30
 
31
  # Getting Image
32
- if 'image' not in request.files:
33
  print("### Nessuna immagine ricevuta ###") # Stampa per il debug
34
  return "No image file in request", 400
35
 
36
- image_file = request.files['image']
 
37
  try:
38
- image = Image.open(image_file)
 
39
  print("### Immagine aperta con successo ###") # Stampa per il debug
40
  except Exception as e:
41
  print(f"### Errore nell'apertura dell'immagine: {str(e)} ###") # Stampa per il debug
 
6
  from model.src.utils.arg_parser import eval_parse_args # Nuovo import corretto
7
  import sys
8
  from PIL import Image
9
+ import base64
10
+
11
 
12
  from model.src import eval
13
 
 
31
  print("### JSON ricevuto:", json_data_from_req) # Stampa per il debug
32
 
33
  # Getting Image
34
+ if 'image' not in json_data_from_req:
35
  print("### Nessuna immagine ricevuta ###") # Stampa per il debug
36
  return "No image file in request", 400
37
 
38
+ encoded_image = json_data_from_req['image']
39
+
40
  try:
41
+ image_data = base64.b64decode(encoded_image)
42
+ image = Image.open(io.BytesIO(image_data))
43
  print("### Immagine aperta con successo ###") # Stampa per il debug
44
  except Exception as e:
45
  print(f"### Errore nell'apertura dell'immagine: {str(e)} ###") # Stampa per il debug