Spaces:
Running
Running
File size: 4,743 Bytes
2792168 e31d991 2792168 e31d991 2792168 e31d991 2792168 e31d991 2792168 e31d991 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 |
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>
.stApp {
max-width: 1200px;
margin: 0 auto;
}
.upload-box {
border: 2px dashed #4c4c4c;
border-radius: 10px;
padding: 20px;
text-align: center;
margin: 10px 0;
}
.output-box {
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 20px;
margin: 20px 0;
background-color: #f8f9fa;
}
.renesistech-header {
background-color: #ffffff;
padding: 20px;
margin-bottom: 30px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
text-align: center;
}
.renesistech-footer {
background-color: #f8f9fa;
padding: 20px;
text-align: center;
border-top: 1px solid #e0e0e0;
margin-top: 40px;
}
</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..."):
output_path = virtual_try_on(garment_url, person_url, 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) |