lcjln commited on
Commit
62a9a6a
Β·
verified Β·
1 Parent(s): e512cee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -49
app.py CHANGED
@@ -93,10 +93,21 @@ def crawl_chats(vod_url):
93
  return "\n".join(chat_logs), chat_counts, laugh_counts
94
 
95
  # λ²„νŠΌμ„ λˆŒλ €μ„ λ•Œ μ±„νŒ… 크둀링 μ‹œμž‘
 
 
 
 
 
 
 
96
  if st.button("크둀링 μ‹œμž‘"):
97
  if vod_url:
98
  chat_logs, chat_counts, laugh_counts = crawl_chats(vod_url)
99
 
 
 
 
 
100
  # 파일둜 μ €μž₯
101
  file_name = "chat_logs.txt"
102
  with open(file_name, "w") as file:
@@ -110,53 +121,52 @@ if st.button("크둀링 μ‹œμž‘"):
110
  file_name=file_name,
111
  mime="text/plain"
112
  )
113
-
114
- # κ·Έλž˜ν”„ 좜λ ₯
115
- if chat_counts and laugh_counts:
116
- # λ°μ΄ν„°ν”„λ ˆμž„ 생성
117
- times = [time.strftime('%H:%M:%S') for time in chat_counts.keys()]
118
- chat_numbers = list(chat_counts.values())
119
- laugh_numbers = [laugh_counts.get(time, 0) for time in chat_counts.keys()]
120
- df = pd.DataFrame({'μ‹œκ°„': times, '전체 μ±„νŒ… 개수': chat_numbers, 'γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수': laugh_numbers})
121
-
122
- # Plotly μ„  κ·Έλž˜ν”„ 그리기
123
- fig = go.Figure()
124
-
125
- # 전체 μ±„νŒ… 개수 μ„  κ·Έλž˜ν”„ μΆ”κ°€
126
- fig.add_trace(go.Scatter(
127
- x=df['μ‹œκ°„'],
128
- y=df['전체 μ±„νŒ… 개수'],
129
- mode='lines', # 마컀 없이 μ„ λ§Œ ν‘œμ‹œ
130
- name='전체 μ±„νŒ… 개수',
131
- line=dict(color='blue'),
132
- hovertemplate='%{x} - 전체 μ±„νŒ… 개수: %{y}<extra></extra>'
133
- ))
134
-
135
- # γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수 μ„  κ·Έλž˜ν”„ μΆ”κ°€
136
- fig.add_trace(go.Scatter(
137
- x=df['μ‹œκ°„'],
138
- y=df['γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수'],
139
- mode='lines', # 마컀 없이 μ„ λ§Œ ν‘œμ‹œ
140
- name='γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수',
141
- line=dict(color='red'),
142
- hovertemplate='%{x} - γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수: %{y}<extra></extra>'
143
- ))
144
-
145
- # κ·Έλž˜ν”„ λ ˆμ΄μ•„μ›ƒ μ„€μ •
146
- fig.update_layout(
147
- title="λΆ„λ‹Ή μ±„νŒ… 및 γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수",
148
- xaxis_title="μ‹œκ°„",
149
- yaxis_title="μ±„νŒ… 개수",
150
- xaxis=dict(
151
- showticklabels=True # xμΆ• μ‹œκ°„ λ ˆμ΄λΈ” ν‘œμ‹œ
152
- ),
153
- hovermode="x unified", # 마우슀λ₯Ό μ˜¬λ Έμ„ λ•Œ ν•΄λ‹Ή xμΆ•μ—μ„œ 툴팁 ν‘œμ‹œ
154
- showlegend=True, # λ²”λ‘€ ν‘œμ‹œ
155
- margin=dict(l=50, r=50, t=100, b=100) # κ·Έλž˜ν”„ μ•„λž˜μͺ½ 여백을 μ‘°μ •
156
- )
157
-
158
- # κ·Έλž˜ν”„ 좜λ ₯
159
- st.plotly_chart(fig)
160
-
161
  else:
162
- st.warning("URL을 μž…λ ₯ν•˜μ„Έμš”.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  return "\n".join(chat_logs), chat_counts, laugh_counts
94
 
95
  # λ²„νŠΌμ„ λˆŒλ €μ„ λ•Œ μ±„νŒ… 크둀링 μ‹œμž‘
96
+ if 'chat_logs' not in st.session_state:
97
+ st.session_state['chat_logs'] = None
98
+ if 'chat_counts' not in st.session_state:
99
+ st.session_state['chat_counts'] = None
100
+ if 'laugh_counts' not in st.session_state:
101
+ st.session_state['laugh_counts'] = None
102
+
103
  if st.button("크둀링 μ‹œμž‘"):
104
  if vod_url:
105
  chat_logs, chat_counts, laugh_counts = crawl_chats(vod_url)
106
 
107
+ st.session_state['chat_logs'] = chat_logs
108
+ st.session_state['chat_counts'] = chat_counts
109
+ st.session_state['laugh_counts'] = laugh_counts
110
+
111
  # 파일둜 μ €μž₯
112
  file_name = "chat_logs.txt"
113
  with open(file_name, "w") as file:
 
121
  file_name=file_name,
122
  mime="text/plain"
123
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  else:
125
+ st.warning("URL을 μž…λ ₯ν•˜μ„Έμš”.")
126
+
127
+ # 이전에 ν¬λ‘€λ§ν•œ κ²°κ³Όκ°€ 있으면 κ·Έλž˜ν”„μ™€ λ‹€μš΄λ‘œλ“œ λ²„νŠΌ ν‘œμ‹œ
128
+ if st.session_state['chat_logs']:
129
+ # λ°μ΄ν„°ν”„λ ˆμž„ 생성
130
+ times = [time.strftime('%H:%M:%S') for time in st.session_state['chat_counts'].keys()]
131
+ chat_numbers = list(st.session_state['chat_counts'].values())
132
+ laugh_numbers = [st.session_state['laugh_counts'].get(time, 0) for time in st.session_state['chat_counts'].keys()]
133
+ df = pd.DataFrame({'μ‹œκ°„': times, '전체 μ±„νŒ… 개수': chat_numbers, 'γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수': laugh_numbers})
134
+
135
+ # Plotly μ„  κ·Έλž˜ν”„ 그리기
136
+ fig = go.Figure()
137
+
138
+ # 전체 μ±„νŒ… 개수 μ„  κ·Έλž˜ν”„ μΆ”κ°€
139
+ fig.add_trace(go.Scatter(
140
+ x=df['μ‹œκ°„'],
141
+ y=df['전체 μ±„νŒ… 개수'],
142
+ mode='lines', # 마컀 없이 μ„ λ§Œ ν‘œμ‹œ
143
+ name='전체 μ±„νŒ… 개수',
144
+ line=dict(color='blue'),
145
+ hovertemplate='%{x} - 전체 μ±„νŒ… 개수: %{y}<extra></extra>'
146
+ ))
147
+
148
+ # γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수 μ„  κ·Έλž˜ν”„ μΆ”κ°€
149
+ fig.add_trace(go.Scatter(
150
+ x=df['μ‹œκ°„'],
151
+ y=df['γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수'],
152
+ mode='lines', # 마컀 없이 μ„ λ§Œ ν‘œμ‹œ
153
+ name='γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수',
154
+ line=dict(color='red'),
155
+ hovertemplate='%{x} - γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수: %{y}<extra></extra>'
156
+ ))
157
+
158
+ # κ·Έλž˜ν”„ λ ˆμ΄μ•„μ›ƒ μ„€μ •
159
+ fig.update_layout(
160
+ title="λΆ„λ‹Ή μ±„νŒ… 및 γ…‹γ…‹γ…‹γ…‹ μ±„νŒ… 개수",
161
+ xaxis_title="μ‹œκ°„",
162
+ yaxis_title="μ±„νŒ… 개수",
163
+ xaxis=dict(
164
+ showticklabels=True # xμΆ• μ‹œκ°„ λ ˆμ΄λΈ” ν‘œμ‹œ
165
+ ),
166
+ hovermode="x unified", # 마우슀λ₯Ό μ˜¬λ Έμ„ λ•Œ ν•΄λ‹Ή xμΆ•μ—μ„œ 툴팁 ν‘œμ‹œ
167
+ showlegend=True, # λ²”λ‘€ ν‘œμ‹œ
168
+ margin=dict(l=50, r=50, t=100, b=100) # κ·Έλž˜ν”„ μ•„λž˜μͺ½ 여백을 μ‘°μ •
169
+ )
170
+
171
+ # κ·Έλž˜ν”„ 좜λ ₯
172
+ st.plotly_chart(fig)