Spaces:
Paused
Paused
giorgio-caparvi commited on
Commit ·
a3d4937
1
Parent(s): b50cfaf
handling images
Browse files- api/app.py +12 -35
api/app.py
CHANGED
|
@@ -11,35 +11,23 @@ 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=['GET'])
|
| 41 |
def generate_design():
|
| 42 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Creiamo una lista di argomenti come quelli che passeresti via CLI
|
| 44 |
sys.argv = [
|
| 45 |
'eval.py',
|
|
@@ -56,22 +44,11 @@ def generate_design():
|
|
| 56 |
# Esegui la funzione `main()` di eval.py passando gli argomenti
|
| 57 |
final_image = eval.main()
|
| 58 |
|
| 59 |
-
|
| 60 |
-
save_path = os.path.join(os.getcwd(), 'generated_image.jpg')
|
| 61 |
-
#final_image.save(save_path, 'JPEG') # Save the image in the current directory
|
| 62 |
-
|
| 63 |
-
# Print the contents of the current directory
|
| 64 |
-
#print("Files in current directory:")
|
| 65 |
-
#for file_name in os.listdir(os.getcwd()):
|
| 66 |
-
# print(file_name)
|
| 67 |
-
|
| 68 |
-
# Also save the image to a BytesIO buffer to return via HTTP
|
| 69 |
img_io = io.BytesIO()
|
| 70 |
final_image.save(img_io, 'JPEG')
|
| 71 |
img_io.seek(0)
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
# Return the image as a file download
|
| 76 |
return send_file(img_io, mimetype='image/jpeg', as_attachment=True, download_name='in memory_image.jpg')
|
| 77 |
|
|
|
|
| 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=['POST'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def generate_design():
|
| 20 |
try:
|
| 21 |
+
|
| 22 |
+
# Getting Image
|
| 23 |
+
image_file = request.files['image']
|
| 24 |
+
image = Image.open(image_file)
|
| 25 |
+
save_path = os.path.join('/api/model/assets/data/vitonhd/test/im_sketch', '03191_00.jpeg')
|
| 26 |
+
image.save(save_path, 'JPEG')
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
# Creiamo una lista di argomenti come quelli che passeresti via CLI
|
| 32 |
sys.argv = [
|
| 33 |
'eval.py',
|
|
|
|
| 44 |
# Esegui la funzione `main()` di eval.py passando gli argomenti
|
| 45 |
final_image = eval.main()
|
| 46 |
|
| 47 |
+
# Save the image to a BytesIO buffer to return via HTTP
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
img_io = io.BytesIO()
|
| 49 |
final_image.save(img_io, 'JPEG')
|
| 50 |
img_io.seek(0)
|
| 51 |
|
|
|
|
|
|
|
| 52 |
# Return the image as a file download
|
| 53 |
return send_file(img_io, mimetype='image/jpeg', as_attachment=True, download_name='in memory_image.jpg')
|
| 54 |
|