Spaces:
Paused
Paused
giorgio-caparvi commited on
Commit ·
764f9ac
1
Parent(s): c1d4555
added post and get req
Browse files
api/app.py
CHANGED
|
@@ -11,52 +11,12 @@ from model.src import eval
|
|
| 11 |
app = Flask(__name__)
|
| 12 |
CORS(app)
|
| 13 |
|
| 14 |
-
# Directory di output
|
| 15 |
-
output_dir = '/api/output/generato_paired_paired/images'
|
| 16 |
-
image_filename = '03191_00.jpg'
|
| 17 |
-
|
| 18 |
@app.route('/')
|
| 19 |
def index():
|
| 20 |
-
|
| 21 |
-
# Extract the full URL where the current request was made
|
| 22 |
-
full_url = request.url
|
| 23 |
-
|
| 24 |
-
# Log the current endpoint to the server logs
|
| 25 |
-
print(f"Current Endpoint: {full_url}")
|
| 26 |
-
|
| 27 |
return render_template('index.html')
|
| 28 |
|
| 29 |
-
@app.route('/
|
| 30 |
-
def current_endpoint():
|
| 31 |
-
# Extract the full URL where the current request was made
|
| 32 |
-
full_url = request.url
|
| 33 |
-
|
| 34 |
-
# Log the current endpoint to the server logs
|
| 35 |
-
print(f"Current Endpoint: {full_url}")
|
| 36 |
-
|
| 37 |
-
# Return the current URL to the client
|
| 38 |
-
return f"Current Endpoint: {full_url}"
|
| 39 |
-
|
| 40 |
-
@app.route('/generate-design', methods=['POST'])
|
| 41 |
def generate_design():
|
| 42 |
-
|
| 43 |
-
'''# Esegui il comando di generazione
|
| 44 |
-
command = [
|
| 45 |
-
'python', '/api/model/src/eval.py',
|
| 46 |
-
'--dataset_path', '/api/model/assets/data/vitonhd',
|
| 47 |
-
'--batch_size', '1',
|
| 48 |
-
'--mixed_precision', 'fp16',
|
| 49 |
-
'--output_dir', output_dir,
|
| 50 |
-
'--save_name', 'generato_paired',
|
| 51 |
-
'--num_workers_test', '4',
|
| 52 |
-
'--sketch_cond_rate', '0.2',
|
| 53 |
-
'--dataset', 'vitonhd',
|
| 54 |
-
'--start_cond_rate', '0.0',
|
| 55 |
-
'--test_order', 'unpaired'
|
| 56 |
-
]
|
| 57 |
-
|
| 58 |
-
# Esegui il comando senza gestire il JSON, lascia che l'errore venga stampato
|
| 59 |
-
subprocess.run(command, check=True)'''
|
| 60 |
try:
|
| 61 |
# Creiamo una lista di argomenti come quelli che passeresti via CLI
|
| 62 |
sys.argv = [
|
|
@@ -75,28 +35,16 @@ def generate_design():
|
|
| 75 |
|
| 76 |
# Esegui la funzione `main()` di eval.py passando gli argomenti
|
| 77 |
final_image = eval.main()
|
| 78 |
-
|
| 79 |
-
# Save the image to the current directory
|
| 80 |
-
save_path = os.path.join(os.getcwd(), 'generated_image.jpg')
|
| 81 |
-
#final_image.save(save_path, 'JPEG') # Save the image in the current directory
|
| 82 |
-
|
| 83 |
-
# Print the contents of the current directory
|
| 84 |
-
#print("Files in current directory:")
|
| 85 |
-
#for file_name in os.listdir(os.getcwd()):
|
| 86 |
-
# print(file_name)
|
| 87 |
-
|
| 88 |
# Also save the image to a BytesIO buffer to return via HTTP
|
| 89 |
img_io = io.BytesIO()
|
| 90 |
final_image.save(img_io, 'JPEG')
|
| 91 |
img_io.seek(0)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
# Return the image as a file download
|
| 96 |
-
return send_file(img_io, mimetype='image/jpeg', as_attachment=True, download_name='
|
| 97 |
|
| 98 |
except Exception as e:
|
| 99 |
return str(e), 500
|
| 100 |
|
| 101 |
if __name__ == '__main__':
|
| 102 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 11 |
app = Flask(__name__)
|
| 12 |
CORS(app)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@app.route('/')
|
| 15 |
def index():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return render_template('index.html')
|
| 17 |
|
| 18 |
+
@app.route('/generate-design', methods=['GET', 'POST'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def generate_design():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
try:
|
| 21 |
# Creiamo una lista di argomenti come quelli che passeresti via CLI
|
| 22 |
sys.argv = [
|
|
|
|
| 35 |
|
| 36 |
# Esegui la funzione `main()` di eval.py passando gli argomenti
|
| 37 |
final_image = eval.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Also save the image to a BytesIO buffer to return via HTTP
|
| 39 |
img_io = io.BytesIO()
|
| 40 |
final_image.save(img_io, 'JPEG')
|
| 41 |
img_io.seek(0)
|
| 42 |
|
|
|
|
|
|
|
| 43 |
# Return the image as a file download
|
| 44 |
+
return send_file(img_io, mimetype='image/jpeg', as_attachment=True, download_name='inmemory_image.jpg')
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
return str(e), 500
|
| 48 |
|
| 49 |
if __name__ == '__main__':
|
| 50 |
+
app.run(host='0.0.0.0', port=7860)
|
api/model/assets/data/vitonhd/test/im_sketch/{03191_00.png → old_03191_00.png}
RENAMED
|
File without changes
|