Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,39 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
from genai import gen_vton
|
4 |
-
from werkzeug.utils import secure_filename
|
5 |
import os
|
6 |
import tempfile
|
|
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
filename = secure_filename(user_image_t.filename)
|
41 |
-
temp_path_1 = os.path.join(temp_dir, filename)
|
42 |
-
user_image_t.save(temp_path_1)
|
43 |
-
user_image = temp_path_1
|
44 |
-
|
45 |
-
gen_vton(user_image, dress_image)
|
46 |
-
processed_image_1_path = './processed_images/output_image.jpg'
|
47 |
-
processed_image_2_path = './processed_images/output_image_1.jpg'
|
48 |
-
|
49 |
-
# Save your images using the paths above...
|
50 |
-
|
51 |
-
# Return the URL for the saved images
|
52 |
-
url_to_processed_image_1 = request.host_url + processed_image_1_path
|
53 |
-
url_to_processed_image_2 = request.host_url + processed_image_2_path
|
54 |
-
# Process images...
|
55 |
-
# For the sake of this example, let's say the processing function returns two image URLs
|
56 |
-
processed_image_urls = [url_to_processed_image_1, url_to_processed_image_2]
|
57 |
-
os.remove(temp_path)
|
58 |
-
os.remove(temp_path_1)
|
59 |
-
return jsonify({'processedImages': processed_image_urls})
|
60 |
-
|
61 |
-
@app.route('/processed_images/<filename>')
|
62 |
-
def processed_images(filename):
|
63 |
-
print("request_came_here")
|
64 |
-
return send_from_directory(app.static_folder, filename)
|
65 |
-
# Example of generating a unique filename for the output
|
66 |
-
|
67 |
-
|
68 |
-
#
|
69 |
-
|
70 |
-
if __name__ == '__main__':
|
71 |
-
app.run()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
|
|
|
|
3 |
import os
|
4 |
import tempfile
|
5 |
+
from genai import gen_vton
|
6 |
+
from werkzeug.utils import secure_filename
|
7 |
|
8 |
+
# Define a function to save the uploaded file to a temporary directory
|
9 |
+
def save_uploaded_file(uploaded_file):
|
10 |
+
try:
|
11 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix="." + uploaded_file.name.split('.')[1]) as tmp:
|
12 |
+
tmp.write(uploaded_file.getbuffer())
|
13 |
+
return tmp.name
|
14 |
+
except Exception as e:
|
15 |
+
return None
|
16 |
+
|
17 |
+
# Streamlit UI components
|
18 |
+
st.title('Image Processing with gen_vton')
|
19 |
+
|
20 |
+
# File uploader for the user and dress images
|
21 |
+
user_image_up = st.file_uploader("Upload User Image", type=['jpg', 'png', 'jpeg'])
|
22 |
+
dress_image_up = st.file_uploader("Upload Dress Image", type=['jpg', 'png', 'jpeg'])
|
23 |
+
|
24 |
+
# Process the images once both are uploaded and a button is pressed
|
25 |
+
if user_image_up and dress_image_up and st.button('Process Images'):
|
26 |
+
user_image_path = save_uploaded_file(user_image_up)
|
27 |
+
dress_image_path = save_uploaded_file(dress_image_up)
|
28 |
+
|
29 |
+
# Assuming gen_vton processes the images and saves them somewhere
|
30 |
+
processed_image_paths = gen_vton(user_image_path, dress_image_path) # Adjust based on actual return value
|
31 |
+
|
32 |
+
# Displaying processed images (assuming gen_vton returns paths to processed images)
|
33 |
+
if processed_image_paths:
|
34 |
+
for image_path in processed_image_paths:
|
35 |
+
st.image(image_path, use_column_width=True)
|
36 |
+
|
37 |
+
# Clean up temporary files
|
38 |
+
os.remove(user_image_path)
|
39 |
+
os.remove(dress_image_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|