Spaces:
Runtime error
Runtime error
myquyen242
commited on
Commit
โข
81aa782
1
Parent(s):
b71851b
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import pandas_bokeh
|
5 |
+
import seaborn as sns
|
6 |
+
from pytrends.request import TrendReq
|
7 |
+
import time
|
8 |
+
import random
|
9 |
+
# ๊ธ ์ฐ๊ธฐ(๋งํฌ ์ฝ์
)
|
10 |
+
st.title('VIETNAM DONGDAEMUN FOOOOOOOOOD!!!!!!!!!')
|
11 |
+
|
12 |
+
st.header('Selection of Vietnamese Restaurants in Dongdaemun Area')
|
13 |
+
st.subheader('Variety of dishes from different region in Vietnam, made affordable and delicious for local taste')
|
14 |
+
st.subheader('Items such as Pho Soup, Bun Bo Hue, Cha Gio or Com Chien')
|
15 |
+
st.write('''Write something here about the booming of Vietnamese Restaurant in Korea - particularly the fast growing food scene in Dongdaemun [ํธ๋ํธ๋ญ](https://namu.wiki/w/%EB%B2%A0%ED%8A%B8%EB%82%A8%20%EC%9A%94%EB%A6%AC)
|
16 |
+
.''' )
|
17 |
+
|
18 |
+
# ์ฌ์ง ์ฝ์
|
19 |
+
st.image('final_image_2.jpg', caption='A Spread of Vietnamese Dishes You Might Be Able To Find')
|
20 |
+
|
21 |
+
st.image('final_image_4.jpg', caption='A popular choice everywhere: Vietnamese Pho Soup')
|
22 |
+
|
23 |
+
st.image('final_image_3.jpg', caption='Hidden Gem: Banh Xeo')
|
24 |
+
|
25 |
+
|
26 |
+
st.header('Cheap and Delicious: One can find a variety of Vietnamese Restaurant in Dongdaemun Area')
|
27 |
+
st.subheader('Hosting dishes from North to South Vietnam')
|
28 |
+
st.subheader('The almost infinite choices will leave you looking for reviews!')
|
29 |
+
st.write('''Before deciding on which dish you'd want ~ carefully browse through the Blog section for an intimate look at the local food joints''' )
|
30 |
+
|
31 |
+
# ๋ฐ์ดํฐ ๋ณด์ฌ์ฃผ๊ธฐ
|
32 |
+
df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง = pd.read_excel('vietnam_food_dongdaemun_BLOGS.xlsx', index_col=0)
|
33 |
+
st.write('We have narrowed down to 150 most relevant blogs!!',df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง)
|
34 |
+
|
35 |
+
df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_keyword = pd.read_excel('vietnam_food_KEYWORDS.xlsx', index_col=0)
|
36 |
+
st.write('๋ธ๋ก๊ทธ ๊ธ์์ ๊ฐ์ฅ ๋ง์ด ์ถํํ ๋จ์ด๋ ~~~ ์ค๋ช
~~~', df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_keyword)
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
# ์๋ํด๋ผ์ฐ๋ - WORDCLOUD
|
41 |
+
st.write('์ฃผ์ ๋จ์ด๋ค์ ์๋ํด๋ผ์ฐ๋๋ก ๋ณด์ฌ์ฃผ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค')
|
42 |
+
st.image('final_WORDCLOUD.png')
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
# ์ฐ๊ฒฐ๋ง ๋ถ์ - NETWORK
|
47 |
+
st.write('''์ทจ์ฌํ์ ์ฃผ์ ๋จ์ด๋ค ๊ฐ์ ๊ณต๋์ถํํ๋ ๊ด๊ณ๋ฅผ ๋ฐํ์ผ๋ก ์๋ฏธ์ฐ๊ฒฐ๋ง์ ๊ทธ๋ ค๋ณด์๋ค.
|
48 |
+
๋ถ์๊ฒฐ๊ณผ, ~~์ค๋ช
~~''')
|
49 |
+
st.image('final_NETWORK.png')
|
50 |
+
|
51 |
+
#### The Section Below Is Extra Stuff We Gotta Think About
|
52 |
+
|
53 |
+
#
|
54 |
+
df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_2 = pd.read_excel('vietnam_food_dongdaemun_BLOGS.xlsx', index_col=0)
|
55 |
+
st.write('Again, the list of blog posts on Dongdaemun Vietnamese Restaurant', df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_2)
|
56 |
+
|
57 |
+
# ๊ฒ์์ด ์
๋ ฅ ๋ฐ์ ์ถ๋ ฅ
|
58 |
+
query = st.text_input('Enter Keyword such as: food name, restaurant name', key='region1_input')
|
59 |
+
df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_2['select1']=df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_2['text'].apply(lambda x: 1 if query in x else 0)
|
60 |
+
st.write('๊ฒ์ ๊ฒฐ๊ณผ:', df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_2[df_๋๋๋ฌธ๊ตฌ_๋ฒ ํธ๋จ_๋ง์ง_2['select1']==1])
|
61 |
+
|
62 |
+
##### HEATMAP #####
|
63 |
+
|
64 |
+
|
65 |
+
# List of user-agents to rotate
|
66 |
+
USER_AGENTS = [
|
67 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
|
68 |
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0',
|
69 |
+
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
|
70 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0'
|
71 |
+
]
|
72 |
+
|
73 |
+
def fetch_trends_data(kw_list, timeframe, geo):
|
74 |
+
pytrends = TrendReq(hl='en-US', tz=360)
|
75 |
+
pytrends.build_payload(kw_list, timeframe=timeframe, geo=geo)
|
76 |
+
df_trends = pytrends.interest_over_time()
|
77 |
+
|
78 |
+
# Introduce random delays to avoid being blocked
|
79 |
+
time.sleep(random.uniform(1, 5))
|
80 |
+
|
81 |
+
# Rotate user-agents
|
82 |
+
user_agent = random.choice(USER_AGENTS)
|
83 |
+
pytrends = TrendReq(hl='en-US', tz=360, custom_useragent=user_agent)
|
84 |
+
pytrends.build_payload(kw_list, timeframe=timeframe, geo=geo)
|
85 |
+
df_trends = pytrends.interest_over_time()
|
86 |
+
|
87 |
+
return df_trends
|
88 |
+
|
89 |
+
# Fetch data for the year 2023
|
90 |
+
kw_list = ['๋ฒ ํธ๋จ ์์']
|
91 |
+
timeframe = '2023-01-01 2023-12-31'
|
92 |
+
geo = 'KR'
|
93 |
+
|
94 |
+
df_trends = fetch_trends_data(kw_list, timeframe, geo)
|
95 |
+
|
96 |
+
# Streamlit app
|
97 |
+
st.title('Monthly Google Trends Data for Vietnamese Food in Seoul (2023)')
|
98 |
+
if not df_trends.empty:
|
99 |
+
df_trends = df_trends.drop(columns=['isPartial'])
|
100 |
+
df_trends.reset_index(inplace=True)
|
101 |
+
|
102 |
+
# Extract month from date
|
103 |
+
df_trends['month'] = df_trends['date'].dt.to_period('M')
|
104 |
+
monthly_counts = df_trends.groupby('month')[kw_list].sum().reset_index()
|
105 |
+
|
106 |
+
# Display the data
|
107 |
+
st.write('Number of searches for each month:')
|
108 |
+
st.write(monthly_counts)
|
109 |
+
|
110 |
+
# Create the heatmap
|
111 |
+
plt.figure(figsize=(10, 6))
|
112 |
+
monthly_counts_pivot = monthly_counts.pivot_table(index='month', values=kw_list)
|
113 |
+
sns.heatmap(monthly_counts_pivot.T, annot=True, fmt="d", cmap='YlGnBu', cbar=False)
|
114 |
+
st.pyplot(plt)
|
115 |
+
else:
|
116 |
+
st.write("No data received from Google Trends.")
|
117 |
+
|
118 |
+
# ๊ตํต์ฌ๊ณ ์ ํ๊ณผ ์ฐ๋์ ๋ฐ๋ฅธ pivot table ๋ณด์ฌ์ฃผ๊ธฐ
|
119 |
+
#df_๊ตํต์ฌ๊ณ _pivot=df_๊ตํต์ฌ๊ณ .pivot_table(index='์ฌ๊ณ ์ ํ๊ตฌ๋ถ', columns='์ฌ๊ณ ์ฐ๋', values='์ฌ๊ณ ๊ฑด์', aggfunc='sum')
|
120 |
+
#df_๊ตํต์ฌ๊ณ _heatmap=df_๊ตํต์ฌ๊ณ _pivot.style.background_gradient(cmap='Oranges').format("{:.2f}")
|
121 |
+
#st.write('๋ค์ ํ๋ ๊ตํต์ฌ๊ณ ๊ฑด์๋ฅผ ์ ํ๊ณผ ์ฐ๋์ ๋ฐ๋ผ ๊ตฌ๋ถํ ๊ฒ์ด๋ค', df_๊ตํต์ฌ๊ณ _heatmap)
|
122 |
+
|
123 |
+
# ๊ฒ์์ด ์
๋ ฅ ๋ฐ์ pivot table ์ถ๋ ฅ
|
124 |
+
#query_pivot = st.text_input('์ด ๊ณณ์ ์ง์ญ๋ช
(์๊ตฐ๊ตฌ)์ ์
๋ ฅํ๋ฉด ๊ด๋ จ ๋ฐ์ดํฐ๋ง ๊ฒ์ํด ๋ณด์ฌ์ค๋๋ค', key='region2_input')
|
125 |
+
#df_๊ตํต์ฌ๊ณ ['select2']=df_๊ตํต์ฌ๊ณ ['์ฌ๊ณ ์ง์ญ์์น๋ช
'].apply(lambda x: 1 if query_pivot in x else 0)
|
126 |
+
#df_๊ตํต์ฌ๊ณ _pivot_selected=df_๊ตํต์ฌ๊ณ [df_๊ตํต์ฌ๊ณ ['select2']==1].pivot_table(index='์ฌ๊ณ ์ ํ๊ตฌ๋ถ', columns='์ฌ๊ณ ์ฐ๋', values='์ฌ๊ณ ๊ฑด์', aggfunc='sum')
|
127 |
+
#df_๊ตํต์ฌ๊ณ _heatmap_selected=df_๊ตํต์ฌ๊ณ _pivot_selected.style.background_gradient(cmap='Oranges').format("{:.2f}")
|
128 |
+
#st.write('๊ฒ์ ๊ฒฐ๊ณผ:', df_๊ตํต์ฌ๊ณ _heatmap_selected)
|
129 |
+
|
130 |
+
# pandas_bokeh ๊ทธ๋ํ ๋ณด์ฌ์ฃผ๊ธฐ
|
131 |
+
#st.write('์ ๊ตญ ๊ตํต์ฌ๊ณ ๋ฐ์ดํฐ์ ๋ฐ๋ฅด๋ฉด, ์ฌ๊ณ ๊ฑด์์ ์ค์์์๋ ๋ฐ์ ํ ๊ด๋ จ์ ๋งบ๊ณ ์๋ค. ~~~์ค๋ช
~~. *๊ทธ๋ํ ๋ด ์ ์ ์ปค์๋ฅผ ๋๋ฉด ์ง์ญ๋ช
์ด ๋ํ๋๋ค')
|
132 |
+
#p_scatter = df_๊ตํต์ฌ๊ณ .plot_bokeh.scatter(
|
133 |
+
# x="์ฌ๊ณ ๊ฑด์",
|
134 |
+
# y="์ค์์์",
|
135 |
+
# title="์ฌ๊ณ ๊ฑด์์ ์ค์์์",
|
136 |
+
# size=10,
|
137 |
+
# hovertool_string="""<h6>์์น:@{์ฌ๊ณ ์ง์ญ์์น๋ช
}</h6>"""
|
138 |
+
#)
|
139 |
+
#st.bokeh_chart(p_scatter, use_container_width=True)
|
140 |
+
|
141 |
+
# ์ ํํ ์กฐ๊ฑด์ ๋ฐ๋ผ ์ถ๋ ฅ
|
142 |
+
#option = st.selectbox('์ฐ๋๋ฅผ ์ ํํ๋ฉด ํด๋น ์๊ธฐ์ ๊ทธ๋ํ๋ฅผ ๋ณด์ฌ์ค๋๋ค',
|
143 |
+
# (2012, 2013, 2014, 2015, 2016, 2018, 2017, 2019, 2020, 2021), key='year_input')
|
144 |
+
|
145 |
+
#p_scatter_selected = df_๊ตํต์ฌ๊ณ [df_๊ตํต์ฌ๊ณ ['์ฌ๊ณ ์ฐ๋']==option].plot_bokeh.scatter(
|
146 |
+
# x="์ฌ๊ณ ๊ฑด์",
|
147 |
+
# y="์ค์์์",
|
148 |
+
# title="์ฌ๊ณ ๊ฑด์์ ์ค์์์",
|
149 |
+
# size=10,
|
150 |
+
# hovertool_string="""<h6>์์น:@{์ฌ๊ณ ์ง์ญ์์น๋ช
}</h6>"""
|
151 |
+
#)
|
152 |
+
#st.write('๊ฒ์ ๊ฒฐ๊ณผ:')
|
153 |
+
#st.bokeh_chart(p_scatter_selected, use_container_width=True)
|