MakiAi's picture
โœจ feat: ใ‚ขใƒ—ใƒชใƒˆใƒƒใƒ—ใƒšใƒผใ‚ธใฎใƒ‡ใ‚ถใ‚คใƒณๆ”นๅ–„
c014942
raw
history blame
2.84 kB
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()