vn_food / app.py
myquyen242's picture
Update app.py
d91049d verified
raw
history blame contribute delete
No virus
6.88 kB
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import pandas_bokeh
import seaborn as sns
import matplotlib.font_manager as fm
import time
import random
# Start of the site here. Include Title, Header and Sub-headers as needed. Also include a paragraph describing what we're trying to show on our site
st.title('์ด์ œ ๋™๋Œ€๋ฌธ์—์„œ ๊ผญ ๋ง›๋ด์•ผ ํ•  ๋ฒ ํŠธ๋‚จ ์Œ์‹ ํŠธ๋ Œ๋“œ!')
st.header('๋ฏธ์‹๊ฐ€ ๋ธ”๋กœ๊ทธ ์ถ”์ฒœ: ๋™๋Œ€๋ฌธ ์ตœ๊ณ ์˜ ๋ฒ ํŠธ๋‚จ ์Œ์‹์  ํƒ๋ฐฉ')
st.subheader('๋ฒ ํŠธ๋‚จ์˜ ๋ง›์„ ํƒํ—˜!! ํ˜„์ง€์—์„œ ์ฆ๊ธธ ์ˆ˜ ์žˆ๋„๋ก ๋ง›์žˆ๊ฒŒ ๋งŒ๋“  ์ €๋ ดํ•œ ์ง€์—ญ ์š”๋ฆฌ')
st.subheader('์Œ€๊ตญ์ˆ˜, ๋ถ„๋ณดํ›„์—, ์งœ์กฐ, ๋˜๋Š” ๋ณถ์Œ๋ฐฅ๊ณผ ๊ฐ™์€ ์Œ์‹')
# I included a link to the namu wikipedia that talks about basic Vietnamese Cuisine and History
st.write('''๋™๋Œ€๋ฌธ์—์„œ [๋ฒ ํŠธ๋‚จ ์š”๋ฆฌ](https://namu.wiki/w/%EB%B2%A0%ED%8A%B8%EB%82%A8%20%EC%9A%94%EB%A6%AC)์˜ ์ธ๊ธฐ๋Š” ๋‹จ์ˆœํ•œ ์ผ์‹œ์ ์ธ ์œ ํ–‰์„ ๋„˜์–ด ์Œ์‹์„ ํ†ตํ•œ ๋ฌธํ™” ๊ต๋ฅ˜์˜ ํž˜์„ ๋ณด์—ฌ์ฃผ๋Š” ์ฆ๊ฑฐ๋‹ค.
ํ•œ๊ตญ์ธ๋“ค์€ ๋ฒ ํŠธ๋‚จ ์š”๋ฆฌ์˜ ๊ฐ•๋ ฌํ•œ ๋ง›๊ณผ ์‹ ์„ ํ•œ ์žฌ๋ฃŒ๋ฅผ ๋ฐ›์•„๋“ค์ด๊ณ  ์žˆ์œผ๋ฉฐ, ๋ฒ ํŠธ๋‚จ ์š”๋ฆฌ์‚ฌ๋“ค์€ ํ˜„์ง€์ธ๋“ค์˜ ์ž…๋ง›์— ๋งž์ถฐ ์กฐ๋ฆฌ๋ฒ•์„ ์กฐ์ •ํ•˜๊ณ  ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์š”๋ฆฌ์˜ ์œตํ•ฉ์€ ๋‹ค์–‘์„ฑ๊ณผ ํ˜์‹ ์„ ๊ธฐ๋…ํ•˜๋Š” ๋™๋Œ€๋ฌธ ์Œ์‹ ๋ฌธํ™”์˜ ์ƒˆ๋กœ์šด ์žฅ์„ ์—ด๊ณ  ์žˆ๋‹ค.
''' )
# Insert photo(s) to support
st.image('final_image_2.jpg', caption='๋ฒ ํŠธ๋‚จ ์ „ํ†ต ์š”๋ฆฌ')
st.write('''ํ–ฅ๊ธ‹ํ•œ ์Œ€๊ตญ์ˆ˜์˜ ๊น€์ด ๋ชจ๋ฝ๋ชจ๋ฝ ํ”ผ์–ด์˜ค๋ฅด๊ณ , ์ “๊ฐ€๋ฝ ๋ถ€๋”ช์น˜๋Š” ์†Œ๋ฆฌ์™€ ํ™œ๊ธฐ์ฐฌ ๋Œ€ํ™”๊ฐ€ ์–ด์šฐ๋Ÿฌ์ง€๋ฉฐ, ์‹ ์„ ํ•œ ํ—ˆ๋ธŒ ํ–ฅ์ด ๊ณต๊ธฐ๋ฅผ ๊ฐ€๋“ ์ฑ„์šด๋‹ค. ์ด๊ณณ์€ ๋ฒ ํŠธ๋‚จ์ด ์•„๋‹ˆ๋ผ, ๋ฒ ํŠธ๋‚จ ์š”๋ฆฌ๊ฐ€ ์ „๋ก€ ์—†๋Š” ์ธ๊ธฐ๋ฅผ ๋ˆ„๋ฆฌ๊ณ  ์žˆ๋Š” ๋™๋Œ€๋ฌธ์ด๋‹ค. ํ•œ๋•Œ ์•„๋Š” ์‚ฌ๋žŒ๋งŒ ์•Œ๋˜ ์ˆจ์€ ๋ณด์„ ๊ฐ™๋˜ ๋ฒ ํŠธ๋‚จ ์‹๋‹น๋“ค์€ ์ด์ œ ๋ฒˆํ™”ํ•œ ๊ฑฐ๋ฆฌ ๊ณณ๊ณณ์— ์ž๋ฆฌ ์žก์•„ ๊ฐ์ž์˜ ๋…ํŠนํ•œ ๋ฐฉ์‹์œผ๋กœ ๋ฒ ํŠธ๋‚จ ์ „ํ†ต ์Œ์‹์„ ์„ ๋ณด๋‹ค.
๋”ฐ๋œปํ•œ ๋ถ„์งœ ํ•œ ๊ทธ๋ฆ‡์ด๋“  ๋ฐ”์‚ญํ•œ ๋ฐ˜์Ž„์˜ค ํ•œ ์ ‘์‹œ๋“ , ๋™๋Œ€๋ฌธ์€ ๋ฒ ํŠธ๋‚จ ๋ฏธ์‹ ์—ฌํ–‰์œผ๋กœ ๊ฐ€๋Š” ํ‹ฐ์ผ“๊ณผ ๊ฐ™๋‹ค.''' )
st.image('final_image_4.jpg', caption='์–ด๋””์„œ๋“  ์‚ฌ๋ž‘๋ฐ›๋Š” ์ธ๊ธฐ ๋ฉ”๋‰ด: ๋ฒ ํŠธ๋‚จ ์Œ€๊ตญ์ˆ˜ (ํฌ)')
st.image('final_image_3.jpg', caption='๋ฐ˜์Ž„์˜ค')
st.header('๋™๋Œ€๋ฌธ, ๋ฒ ํŠธ๋‚จ ๋ฏธ์‹ ์—ฌํ–‰์˜ ์„ฑ์ง€!')
st.subheader('๊ฐ€์„ฑ๋น„ ์ตœ๊ณ ์˜ ๋ฒ ํŠธ๋‚จ ์Œ์‹์„ ์ฐพ์œผ์‹ ๋‹ค๋ฉด ๋™๋Œ€๋ฌธ์ด ์ •๋‹ต์ž…๋‹ˆ๋‹ค')
st.subheader('๋ถ๋ถ€ ํ•˜๋…ธ์ด์˜ ์Œ€๊ตญ์ˆ˜๋ถ€ํ„ฐ ๋‚จ๋ถ€ ํ˜ธ์น˜๋ฏผ์˜ ๋ฐ˜์Ž„์˜ค๊นŒ์ง€, ๋ฒ ํŠธ๋‚จ ์ „์—ญ์˜ ๋‹ค์ฑ„๋กœ์šด ๋ง›์„ ํ•œ ๊ณณ์—์„œ ์ฆ๊ธธ ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ')
st.write('''์–ด๋–ค ๋ง›์ง‘์„ ๊ฐ€์•ผ ํ• ์ง€ ๊ณ ๋ฏผ์ด๋ผ๋ฉด? ๊ฑฑ์ • ๋งˆ์„ธ์š”! 150๊ฐœ ์ด์ƒ์˜ ์—„์„ ๋œ ๋ธ”๋กœ๊ทธ ํ›„๊ธฐ๋ฅผ ํ†ตํ•ด ํ˜„์ง€์ธ๋“ค์ด ์ถ”์ฒœํ•˜๋Š” ์ง„์งœ ๋ง›์ง‘์„ ์ฐพ์•„ ๋– ๋‚˜๋ณด์„ธ์š”. ๋‹น์‹ ์˜ ์ž…๋ง›์„ ์‚ฌ๋กœ์žก์„ ์ธ์ƒ ๋ฒ ํŠธ๋‚จ ์Œ์‹์„ ๋งŒ๋‚˜๊ฒŒ ๋  ๊ฒ๋‹ˆ๋‹ค''' )
# ๋ฐ์ดํ„ฐ ๋ณด์—ฌ์ฃผ๊ธฐ
df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘ = pd.read_excel('vietnam_food_dongdaemun_BLOGS.xlsx', index_col=0)
st.write('',df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘)
df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_keyword = pd.read_excel('vietnam_food_KEYWORDS.xlsx', index_col=0)
st.write('๋ธ”๋กœ๊ทธ ๊ธ€์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์ถœํ˜„ํ•œ ๋‹จ์–ด๋Š” ~~~ ์„ค๋ช…~~~', df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_keyword)
# ์›Œ๋“œํด๋ผ์šฐ๋“œ - WORDCLOUD
st.write('์ฃผ์š” ๋‹จ์–ด๋“ค์„ ์›Œ๋“œํด๋ผ์šฐ๋“œ๋กœ ๋ณด์—ฌ์ฃผ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค')
st.image('final_WORDCLOUD.png')
# ์—ฐ๊ฒฐ๋ง ๋ถ„์„ - NETWORK
st.write('''์ทจ์žฌํŒ€์€ ์ฃผ์š” ๋‹จ์–ด๋“ค ๊ฐ„์— ๊ณต๋™์ถœํ˜„ํ•˜๋Š” ๊ด€๊ณ„๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์˜๋ฏธ์—ฐ๊ฒฐ๋ง์„ ๊ทธ๋ ค๋ณด์•˜๋‹ค.
๋ถ„์„๊ฒฐ๊ณผ, ~~์„ค๋ช…~~''')
st.image('final_NETWORK.png')
##### SEARCHING ####
#
df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_2 = pd.read_excel('vietnam_food_dongdaemun_BLOGS.xlsx', index_col=0)
# ๊ฒ€์ƒ‰์–ด ์ž…๋ ฅ ๋ฐ›์•„ ์ถœ๋ ฅ
query = st.text_input('์Œ์‹ ์ด๋ฆ„, ์‹๋‹น ์ด๋ฆ„ ๋“ฑ์˜ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.', key='region1_input')
df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_2['select1']=df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_2['text'].apply(lambda x: 1 if query in x else 0)
st.write('๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ:', df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_2[df_๋™๋Œ€๋ฌธ๊ตฌ_๋ฒ ํŠธ๋‚จ_๋ง›์ง‘_2['select1']==1])
##### HEATMAP #####
# Load the data from the saved Excel file
file_path_google = 'formatted_google_trends_vietnam_food.xlsx'
file_path_naver = 'naver_trends_vietnam_food.xlsx'
df_google = pd.read_excel(file_path_google, index_col=0)
df_naver = pd.read_excel(file_path_naver, index_col=0)
# Set the font family to a font that supports Korean characters
font_path = 'NanumGothic.ttf' # Update this path to the location of your Korean font
font_name = fm.FontProperties(fname=font_path).get_name()
plt.rc('font', family=font_name)
# Streamlit app
st.title('ํ•œ๊ตญ ๋‚ด "๋ฒ ํŠธ๋‚จ ์Œ์‹" ์›”๋ณ„ ํŠธ๋ Œ๋“œ ๋ฐ์ดํ„ฐ (2022๋…„ vs 2023๋…„)')
# Function to process and display the data
def process_and_display_data(df, source_name):
if not df.empty:
if 'Date' in df.columns:
df['Date'] = pd.to_datetime(df['Date'])
df['Month'] = df['Date'].dt.month
df['Year'] = df['Date'].dt.year
df = df.pivot(index='Year', columns='Month', values='Value')
df.index = df.index.astype(int)
# Convert month numbers to month names
month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
df.columns = month_names
# Normalize the data to improve gradient visibility
df_normalized = (df - df.min().min()) / (df.max().max() - df.min().min())
# Apply background_gradient with normalization
df_heatmap = df_normalized.style.background_gradient(cmap='Oranges').format("{:.2f}")
st.write(f'Number of searches for each month ({source_name}):')
# Create a seaborn heatmap for better visualization since matplot gradient wasn't working
plt.figure(figsize=(12, 4))
sns.heatmap(df, annot=True, fmt=".1f", cmap="Oranges", linewidths=.5, cbar_kws={'label': 'Number of Searches'})
plt.title(f'Monthly {source_name} Trends Data for ๋ฒ ํŠธ๋‚จ ์Œ์‹ in South Korea (2022 vs 2023)', fontsize=22, fontproperties=fm.FontProperties(fname=font_path))
plt.xlabel('Month', fontsize=14, fontproperties=fm.FontProperties(fname=font_path))
plt.ylabel('Year', fontsize=14, fontproperties=fm.FontProperties(fname=font_path))
plt.xticks(rotation=45, fontproperties=fm.FontProperties(fname=font_path))
plt.yticks(rotation=0, fontproperties=fm.FontProperties(fname=font_path))
st.pyplot(plt)
else:
st.write(f"No data available in the {source_name} Excel file.")
# Display Google Trends Data
process_and_display_data(df_google, "Google Trends")
# Display Naver Data Lab Data
process_and_display_data(df_naver, "Naver Data Lab")