File size: 6,495 Bytes
2792168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e31d991
2792168
 
9b51272
2792168
9b51272
2792168
9b51272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2792168
9b51272
 
 
 
 
 
 
2792168
9b51272
 
 
2792168
9b51272
 
 
2792168
9b51272
 
 
2792168
 
9b51272
 
 
 
 
 
 
e31d991
9b51272
e31d991
9b51272
 
e31d991
9b51272
 
e31d991
9b51272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e31d991
2792168
 
 
e31d991
 
 
 
 
 
 
 
2792168
 
 
 
 
 
 
 
 
 
e31d991
 
 
 
 
 
 
 
 
 
 
2792168
 
 
 
e31d991
 
 
 
 
 
 
 
 
 
 
2792168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b51272
 
 
 
 
 
 
2792168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e31d991
2792168
e31d991
 
 
2792168
 
1
2
3
4
5
6
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import streamlit as st
import os
from vton import virtual_try_on
import requests
from PIL import Image
from io import BytesIO

# Set page config for a wider layout and custom title
st.set_page_config(
    page_title="Virtual Try-On App",
    page_icon="πŸ‘”",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS for better styling with Renesistech branding
st.markdown("""
<style>
    /* Global Styles */
    .stApp {
        max-width: 1400px;
        margin: 0 auto;
        background-color: #ffffff;
        font-family: 'Inter', sans-serif;
    }
    
    /* Header Styles */
    .renesistech-header {
        background: linear-gradient(to right, #f8f9fa, #ffffff);
        padding: 2rem;
        margin-bottom: 2rem;
        box-shadow: 0 4px 6px rgba(0,0,0,0.05);
        text-align: center;
        border-bottom: 1px solid #eaeaea;
    }
    
    /* Main Content Styles */
    .stButton > button {
        background-color: #007bff;
        color: white;
        padding: 0.75rem 2rem;
        border-radius: 8px;
        border: none;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    
    .stButton > button:hover {
        background-color: #0056b3;
        transform: translateY(-2px);
    }
    
    /* Upload Box Styles */
    .upload-box {
        border: 2px dashed #e0e0e0;
        border-radius: 12px;
        padding: 2rem;
        text-align: center;
        margin: 1rem 0;
        background-color: #fafafa;
        transition: all 0.3s ease;
    }
    
    .upload-box:hover {
        border-color: #007bff;
        background-color: #f8f9fa;
    }
    
    /* Output Box Styles */
    .output-box {
        border: 1px solid #eaeaea;
        border-radius: 12px;
        padding: 2rem;
        margin: 2rem 0;
        background-color: #ffffff;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    
    /* Footer Styles */
    .renesistech-footer {
        background: linear-gradient(to right, #f8f9fa, #ffffff);
        padding: 2rem;
        text-align: center;
        border-top: 1px solid #eaeaea;
        margin-top: 3rem;
    }
    
    /* Typography Improvements */
    h1, h2, h3, .stMarkdown p {
        color: #2c3e50;
        letter-spacing: -0.5px;
    }
    
    .stTextArea textarea {
        border-radius: 8px;
        border: 1px solid #eaeaea;
        padding: 1rem;
        font-size: 1rem;
    }
    
    .stTextArea textarea:focus {
        border-color: #007bff;
        box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
    }
    
    /* Image Display Improvements */
    .stImage img {
        border-radius: 12px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
</style>
""", unsafe_allow_html=True)

# Add Renesistech header
st.markdown("""
<div class='renesistech-header'>
    <h1 style='color: #333; margin: 0;'>Renesistech</h1>
    <p style='color: #666; margin: 10px 0 0 0;'>Virtual Try-On Solution</p>
</div>
""", unsafe_allow_html=True)

# Title and description
st.title("✨ Virtual Try-On Application")
st.markdown("""Upload a garment image and a person's photo to see how the garment would look on them!""")

# Create two columns for input images
col1, col2 = st.columns(2)

# Garment image upload
with col1:
    st.subheader("Garment Image")
    garment_file = st.file_uploader("Upload garment image", type=["jpg", "jpeg", "png", "webp"], key="garment_upload")
    garment_url = None
    if garment_file:
        st.image(garment_file, caption="Uploaded Garment", use_container_width=True)
        # Save uploaded file to temporary file
        garment_img = Image.open(garment_file)
        garment_buffer = BytesIO()
        garment_img.save(garment_buffer, format="PNG")
        garment_url = "temp_garment.png"
        with open(garment_url, "wb") as f:
            f.write(garment_buffer.getvalue())

# Person image upload
with col2:
    st.subheader("Person Image")
    person_file = st.file_uploader("Upload person image", type=["jpg", "jpeg", "png", "webp"], key="person_upload")
    person_url = None
    if person_file:
        st.image(person_file, caption="Uploaded Person", use_container_width=True)
        # Save uploaded file to temporary file
        person_img = Image.open(person_file)
        person_buffer = BytesIO()
        person_img.save(person_buffer, format="PNG")
        person_url = "temp_person.png"
        with open(person_url, "wb") as f:
            f.write(person_buffer.getvalue())

# Garment description input
st.subheader("Garment Description")
garment_desc = st.text_area(
    "Describe the garment (e.g., color, style, type)",
    height=100,
    placeholder="Example: A cute pink top with floral pattern"
)

# Check for API token
if "REPLICATE_API_TOKEN" not in os.environ:
    st.warning(
        "⚠️ REPLICATE_API_TOKEN is not set. Please set it using: "
        "export REPLICATE_API_TOKEN='your_token_here'"
    )

# Process button
if st.button("Generate Try-On", type="primary"):
    if not (garment_url and person_url and garment_desc):
        st.error("Please provide all required inputs!")
    else:
        try:
            with st.spinner("πŸ”„ Processing virtual try-on..."):
                # Read the image data from the temporary files
                with open(garment_url, 'rb') as f:
                    garment_data = f.read()
                with open(person_url, 'rb') as f:
                    person_data = f.read()
                    
                output_path = virtual_try_on(garment_data, person_data, garment_desc)
                
                # Display result in a styled box
                st.markdown("<div class='output-box'>", unsafe_allow_html=True)
                st.subheader("πŸŽ‰ Try-On Result")
                st.image(output_path, caption="Virtual Try-On Result", use_container_width=True)
                st.markdown("</div>", unsafe_allow_html=True)
                
                # Cleanup temporary files
                if os.path.exists("temp_garment.png"):
                    os.remove("temp_garment.png")
                if os.path.exists("temp_person.png"):
                    os.remove("temp_person.png")
                    
        except Exception as e:
            st.error(f"Error occurred: {str(e)}")

# Renesistech Footer
st.markdown("""
<div class='renesistech-footer'>
    <p style='color: #333; font-weight: bold; margin: 0;'>Β© 2024 Renesistech</p>
    <p style='color: #666; margin: 5px 0 0 0;'>Innovating Fashion Technology</p>
</div>
""", unsafe_allow_html=True)