Spaces:
Sleeping
Sleeping
File size: 4,499 Bytes
2e4c734 f095b1c 84f4a13 2e4c734 f095b1c 805f259 522568b 805f259 2e4c734 f095b1c 2e4c734 f095b1c 805f259 f095b1c 805f259 f095b1c 805f259 f095b1c 805f259 2e4c734 f095b1c 2e4c734 522568b 805f259 522568b 805f259 522568b 805f259 f095b1c 522568b 805f259 522568b f095b1c 805f259 522568b 805f259 2e4c734 f095b1c 805f259 f095b1c 805f259 522568b 805f259 522568b f095b1c 805f259 522568b 805f259 522568b 805f259 f095b1c 805f259 f095b1c 805f259 9592549 f095b1c 522568b 2e4c734 f095b1c 522568b f095b1c |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
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()
|