Spaces:
Runtime error
Runtime error
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") | |