Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
from core import process_header_image | |
def main(): | |
st.markdown(""" | |
<div align="center"> | |
# Pic-to-Header | |
![Pic-to-Header Result](https://raw.githubusercontent.com/Sunwood-ai-labs/pic-to-header/refs/heads/main/assets/result.png) | |
[![GitHub license](https://img.shields.io/github/license/Sunwood-ai-labs/pic-to-header)](https://github.com/Sunwood-ai-labs/pic-to-header/blob/main/LICENSE) | |
[![GitHub stars](https://img.shields.io/github/stars/Sunwood-ai-labs/pic-to-header)](https://github.com/Sunwood-ai-labs/pic-to-header/stargazers) | |
[![GitHub issues](https://img.shields.io/github/issues/Sunwood-ai-labs/pic-to-header)](https://github.com/Sunwood-ai-labs/pic-to-header/issues) | |
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) | |
![Streamlit](https://img.shields.io/badge/Streamlit-FF4B4B?style=for-the-badge&logo=Streamlit&logoColor=white) | |
![OpenCV](https://img.shields.io/badge/opencv-%23white.svg?style=for-the-badge&logo=opencv&logoColor=white) | |
</div> | |
Pic-to-Headerใฏใใในใฏ็ปๅใจๅ ฅๅ็ปๅใไฝฟ็จใใฆใใใใผ็ปๅใ็ๆใใPythonใขใใชใฑใผใทใงใณใงใใ | |
""", unsafe_allow_html=True) | |
st.write("ใในใฏ็ปๅใจๅ ฅๅ็ปๅใใขใใใญใผใใใฆใใใใใผ็ปๅใ็ๆใใพใใ") | |
input_image = st.file_uploader("ๅ ฅๅ็ปๅใใขใใใญใผใ", type=["png", "jpg", "jpeg"]) | |
mask_image = st.file_uploader("ใในใฏ็ปๅใใขใใใญใผใ", type=["png", "jpg", "jpeg"]) | |
if input_image is not None and mask_image is not None: | |
if st.button("ใใใใผ็ปๅใ็ๆ"): | |
# ไธๆใใกใคใซใจใใฆไฟๅญ | |
input_path = f"temp_input.{input_image.name.split('.')[-1]}" | |
mask_path = f"temp_mask.{mask_image.name.split('.')[-1]}" | |
output_path = "output_header.png" | |
with open(input_path, "wb") as f: | |
f.write(input_image.getbuffer()) | |
with open(mask_path, "wb") as f: | |
f.write(mask_image.getbuffer()) | |
# ็ปๅๅฆ็ | |
process_header_image(input_path, mask_path, output_path) | |
# ็ตๆใ่กจ็คบ | |
st.image(output_path, caption="็ๆใใใใใใใผ็ปๅ") | |
# ใใฆใณใญใผใใใฟใณใ่ฟฝๅ | |
with open(output_path, "rb") as file: | |
btn = st.download_button( | |
label="ใใใใผ็ปๅใใใฆใณใญใผใ", | |
data=file, | |
file_name="header_image.png", | |
mime="image/png" | |
) | |
# ไธๆใใกใคใซใๅ้ค | |
os.remove(input_path) | |
os.remove(mask_path) | |
os.remove(output_path) | |
if __name__ == "__main__": | |
main() | |