Spaces:
Paused
Paused
giorgio-caparvi
commited on
Commit
·
2aba367
1
Parent(s):
6baa8bf
updated backend to handle new models
Browse files- api/app.py +24 -7
api/app.py
CHANGED
@@ -51,31 +51,48 @@ def generate_design():
|
|
51 |
print(f"### Errore nell'apertura dell'immagine: {str(e)} ###") # Stampa per il debug
|
52 |
return f"Failed to open the image: {str(e)}", 400
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
|
|
55 |
# Saving sketch in filesystem
|
56 |
model_key = list(json_data_from_req["MODEL"].keys())[0] # Es: "03191"
|
57 |
-
image_filename = f"{model_key}
|
|
|
|
|
58 |
image_save_path = os.path.join(image_save_dir, image_filename)
|
59 |
image.save(image_save_path, format='JPEG')
|
60 |
-
|
61 |
-
with open(text_file_path, "w") as text_file:
|
62 |
-
|
63 |
|
64 |
|
65 |
# Argomenti per eval.main
|
66 |
sys.argv = [
|
67 |
'eval.py',
|
68 |
-
'--dataset_path',
|
69 |
'--batch_size', '1',
|
70 |
'--mixed_precision', 'fp16',
|
71 |
'--num_workers_test', '4',
|
72 |
'--sketch_cond_rate', '0.2',
|
73 |
-
'--dataset',
|
74 |
'--start_cond_rate', '0.0',
|
75 |
'--test_order', 'paired'
|
76 |
]
|
77 |
print("### Esecuzione eval.main ###") # Stampa per il debug
|
78 |
-
|
79 |
import traceback
|
80 |
|
81 |
# Esecuzione del modello
|
|
|
51 |
print(f"### Errore nell'apertura dell'immagine: {str(e)} ###") # Stampa per il debug
|
52 |
return f"Failed to open the image: {str(e)}", 400
|
53 |
|
54 |
+
if 'vitonhd' in json_data_from_req:
|
55 |
+
dataset_name = 'vitonhd'
|
56 |
+
image_suffix = '_00.jpeg'
|
57 |
+
dataset_path = '/api/model/assets/data/vitonhd'
|
58 |
+
image_save_dir = os.path.join(dataset_path, 'test/im_sketch')
|
59 |
+
elif 'dresscode' in json_data_from_req:
|
60 |
+
dataset_name = 'dresscode'
|
61 |
+
image_suffix = '_01.jpeg'
|
62 |
+
body_part = json_data_from_req['body_part']
|
63 |
+
dataset_path = f'/api/model/assets/data/dresscode/{body_part}'
|
64 |
+
image_save_dir = os.path.join(dataset_path, 'im_sketch')
|
65 |
+
else:
|
66 |
+
print("### Chiave 'vitonhd' o 'dresscode' non trovata nel JSON ###") # Stampa per il debug
|
67 |
+
return "Invalid JSON data, expected 'vitonhd' or 'dresscode'", 400
|
68 |
|
69 |
+
|
70 |
# Saving sketch in filesystem
|
71 |
model_key = list(json_data_from_req["MODEL"].keys())[0] # Es: "03191"
|
72 |
+
image_filename = f"{model_key}{image_suffix}" # Nome file immagine es: "03191_00.jpg"
|
73 |
+
print("###################################### NOME SKETCH: ", image_filename)
|
74 |
+
print("###################################### DIRECTORY DOVE LO SALVO: ", image_save_dir)
|
75 |
image_save_path = os.path.join(image_save_dir, image_filename)
|
76 |
image.save(image_save_path, format='JPEG')
|
77 |
+
|
78 |
+
#with open(text_file_path, "w") as text_file:
|
79 |
+
# text_file.write(f"{image_filename} {image_filename}\n")
|
80 |
|
81 |
|
82 |
# Argomenti per eval.main
|
83 |
sys.argv = [
|
84 |
'eval.py',
|
85 |
+
'--dataset_path', dataset_path,
|
86 |
'--batch_size', '1',
|
87 |
'--mixed_precision', 'fp16',
|
88 |
'--num_workers_test', '4',
|
89 |
'--sketch_cond_rate', '0.2',
|
90 |
+
'--dataset', dataset_name,
|
91 |
'--start_cond_rate', '0.0',
|
92 |
'--test_order', 'paired'
|
93 |
]
|
94 |
print("### Esecuzione eval.main ###") # Stampa per il debug
|
95 |
+
|
96 |
import traceback
|
97 |
|
98 |
# Esecuzione del modello
|