import streamlit as st from pyvis.network import Network import random import streamlit.components.v1 as components # 애플리케이션 상태 관리 if "page" not in st.session_state: st.session_state.page = "login" if "influencers" not in st.session_state: st.session_state.influencers = [] if "products" not in st.session_state: st.session_state.products = [] if "matches" not in st.session_state: st.session_state.matches = [] # 페이지 전환 함수 def switch_page(new_page): st.session_state.page = new_page # 로그인 페이지 def login_page(): st.title("로그인 페이지") st.write("계정 정보를 입력하세요.") username = st.text_input("사용자 이름") password = st.text_input("비밀번호", type="password") if st.button("로그인"): if username == "admin" and password == "password123": st.success("로그인 성공!") switch_page("input_data") else: st.error("로그인 실패! 사용자 이름 또는 비밀번호가 잘못되었습니다.") # 데이터 입력 페이지 def input_data_page(): st.title("데이터 입력 페이지") # 예시 데이터 example_influencers = """Cristiano Ronaldo Leo Messi Selena Gomez Kylie Jenner Dwayne Johnson Ariana Grande Kim Kardashian Beyoncé Khloé Kardashian Justin Bieber Kendall Jenner Taylor Swift Virat Kohli Jennifer Lopez Nicki Minaj Neymar Jr Miley Cyrus Katy Perry Zendaya Kevin Hart Cardi B Drake Shawn Mendes Chris Hemsworth Emma Watson""" example_products = """Nike Shoes Adidas T-Shirts Coca-Cola Bottles Samsung Galaxy Phones Apple iPhones Puma Running Gear L'Oreal Makeup Kits Gucci Handbags Prada Sunglasses Rolex Watches Louis Vuitton Wallets Levi's Jeans Sony Headphones Microsoft Surface Laptops Amazon Echo Devices Tesla Model 3 BMW Electric Scooters Starbucks Coffee Beans Netflix Subscriptions Disney+ Streaming Services Uniqlo Jackets H&M Hoodies""" # 인플루언서 입력 st.subheader("인플루언서 입력") influencers_input = st.text_area( "인플루언서 목록 (한 줄에 하나씩 입력하세요)", value=example_influencers, height=200, ) # 상품 입력 st.subheader("상품 입력") products_input = st.text_area( "상품 목록 (한 줄에 하나씩 입력하세요)", value=example_products, height=200, ) if st.button("매칭 시작하기"): influencers = [name.strip() for name in influencers_input.strip().split('\n') if name.strip()] products = [name.strip() for name in products_input.strip().split('\n') if name.strip()] if not influencers or not products: st.error("인플루언서와 상품을 모두 입력해야 합니다.") else: matches = [(influencer, random.choice(products)) for influencer in influencers] st.session_state.influencers = influencers st.session_state.products = products st.session_state.matches = matches switch_page("match_result") # 매칭 결과 페이지 def match_result_page(): st.title("매칭 결과 페이지") if not st.session_state.matches: st.warning("데이터 입력 페이지에서 데이터를 먼저 입력하세요!") return influencers = st.session_state.influencers products = st.session_state.products matches = st.session_state.matches # pyvis 네트워크 생성 net = Network(height='600px', width='100%', bgcolor='#222222', font_color='white') net.toggle_physics(True) # 노드 추가 for influencer in influencers: net.add_node(influencer, label=influencer, color="blue") for product in products: net.add_node(product, label=product, color="green") # 매칭 간선 추가 for influencer, product in matches: net.add_edge(influencer, product, color="red", width=2) # HTML 렌더링 net.show_buttons(filter_=['physics']) net_html = net.generate_html() # 네트워크 그래프 출력 components.html(net_html, height=600) # 매칭 결과 출력 st.subheader("매칭 결과:") for influencer, product in matches: st.write(f"{influencer} ➡️ {product}") # 페이지 라우팅 if st.session_state.page == "login": login_page() elif st.session_state.page == "input_data": input_data_page() elif st.session_state.page == "match_result": match_result_page()