Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,46 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from PIL import Image
|
| 3 |
-
from texture_transfer import create_image_tile, create_layover, create_image_cutout, paste_image
|
| 4 |
-
|
| 5 |
-
st.title("Texture Correction App")
|
| 6 |
-
|
| 7 |
-
if 'clicked' not in st.session_state:
|
| 8 |
-
st.session_state.clicked = False
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def click_button():
|
| 12 |
-
st.session_state.clicked = True
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
with st.sidebar:
|
| 16 |
-
st.text("Play around this values")
|
| 17 |
-
opacity = st.slider("Control opacity", min_value=0.0, max_value=
|
| 18 |
-
|
| 19 |
-
product, generated, texture_correct = st.columns(3)
|
| 20 |
-
with product:
|
| 21 |
-
st.header("Input product texture patch")
|
| 22 |
-
product_image = st.file_uploader("Patch of the Garment(Cut out an area from the garment)",
|
| 23 |
-
type=["png", "jpg", "jpeg"])
|
| 24 |
-
if product_image:
|
| 25 |
-
st.image(product_image)
|
| 26 |
-
|
| 27 |
-
with generated:
|
| 28 |
-
st.header("Input generated product Image & Mask")
|
| 29 |
-
generated_image = st.file_uploader("Generated Image", type=["png", "jpg", "jpeg"])
|
| 30 |
-
gen_image_mask = st.file_uploader("Generated Mask", type=["png", "jpg", "jpeg"])
|
| 31 |
-
if generated_image:
|
| 32 |
-
st.image(generated_image)
|
| 33 |
-
|
| 34 |
-
with texture_correct:
|
| 35 |
-
st.button("Texture Correct", on_click=click_button)
|
| 36 |
-
if st.session_state.clicked:
|
| 37 |
-
with st.spinner("Texture correcting🫡..."):
|
| 38 |
-
product_image = Image.open(generated_image)
|
| 39 |
-
product_image_dim = product_image.size
|
| 40 |
-
x_dim = product_image_dim[0]
|
| 41 |
-
y_dim = product_image_dim[0]
|
| 42 |
-
create_image_tile(product_image, x_dim, y_dim)
|
| 43 |
-
overlay = create_layover(generated_image, 'tiled_image.png', opacity)
|
| 44 |
-
create_image_cutout('lay_over_image.png', gen_image_mask)
|
| 45 |
-
paste_image(generated_image, 'cut_out_image.png', gen_image_mask)
|
| 46 |
-
st.image("result.png", caption="Texture Corrected Image", use_column_width=True)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from texture_transfer import create_image_tile, create_layover, create_image_cutout, paste_image
|
| 4 |
+
|
| 5 |
+
st.title("Texture Correction App")
|
| 6 |
+
|
| 7 |
+
if 'clicked' not in st.session_state:
|
| 8 |
+
st.session_state.clicked = False
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def click_button():
|
| 12 |
+
st.session_state.clicked = True
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
with st.sidebar:
|
| 16 |
+
st.text("Play around this values")
|
| 17 |
+
opacity = st.slider("Control opacity", min_value=0.0, max_value=1.0, value=1.0)
|
| 18 |
+
|
| 19 |
+
product, generated, texture_correct = st.columns(3)
|
| 20 |
+
with product:
|
| 21 |
+
st.header("Input product texture patch")
|
| 22 |
+
product_image = st.file_uploader("Patch of the Garment(Cut out an area from the garment)",
|
| 23 |
+
type=["png", "jpg", "jpeg"])
|
| 24 |
+
if product_image:
|
| 25 |
+
st.image(product_image)
|
| 26 |
+
|
| 27 |
+
with generated:
|
| 28 |
+
st.header("Input generated product Image & Mask")
|
| 29 |
+
generated_image = st.file_uploader("Generated Image", type=["png", "jpg", "jpeg"])
|
| 30 |
+
gen_image_mask = st.file_uploader("Generated Mask", type=["png", "jpg", "jpeg"])
|
| 31 |
+
if generated_image:
|
| 32 |
+
st.image(generated_image)
|
| 33 |
+
|
| 34 |
+
with texture_correct:
|
| 35 |
+
st.button("Texture Correct", on_click=click_button)
|
| 36 |
+
if st.session_state.clicked:
|
| 37 |
+
with st.spinner("Texture correcting🫡..."):
|
| 38 |
+
product_image = Image.open(generated_image)
|
| 39 |
+
product_image_dim = product_image.size
|
| 40 |
+
x_dim = product_image_dim[0]
|
| 41 |
+
y_dim = product_image_dim[0]
|
| 42 |
+
create_image_tile(product_image, x_dim, y_dim)
|
| 43 |
+
overlay = create_layover(generated_image, 'tiled_image.png', opacity)
|
| 44 |
+
create_image_cutout('lay_over_image.png', gen_image_mask)
|
| 45 |
+
paste_image(generated_image, 'cut_out_image.png', gen_image_mask)
|
| 46 |
+
st.image("result.png", caption="Texture Corrected Image", use_column_width=True)
|