File size: 2,842 Bytes
9100260
 
08c4577
9100260
 
c014942
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9100260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()