Update src/streamlit_app.py
Browse files- src/streamlit_app.py +23 -23
src/streamlit_app.py
CHANGED
|
@@ -19,9 +19,8 @@ import os
|
|
| 19 |
from langdetect import detect, DetectorFactory
|
| 20 |
DetectorFactory.seed = 0
|
| 21 |
|
| 22 |
-
|
| 23 |
# ==============================
|
| 24 |
-
# SETTING PATH
|
| 25 |
# ==============================
|
| 26 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 27 |
|
|
@@ -42,7 +41,7 @@ if 'page' not in st.session_state:
|
|
| 42 |
st.session_state.page = "uji_kalimat"
|
| 43 |
|
| 44 |
# ==============================
|
| 45 |
-
# GLOBAL CSS
|
| 46 |
# ==============================
|
| 47 |
st.markdown("""
|
| 48 |
<style>
|
|
@@ -462,7 +461,7 @@ st.markdown("""
|
|
| 462 |
|
| 463 |
|
| 464 |
# ==============================
|
| 465 |
-
# HEADER / NAVBAR
|
| 466 |
# ==============================
|
| 467 |
def set_page(page_name):
|
| 468 |
st.session_state.page = page_name
|
|
@@ -476,7 +475,7 @@ st.markdown("""
|
|
| 476 |
</div>
|
| 477 |
""", unsafe_allow_html=True)
|
| 478 |
|
| 479 |
-
|
| 480 |
nav_col_pad, nav_col1, nav_col2, nav_col_end = st.columns([6, 1, 1, 1])
|
| 481 |
|
| 482 |
with nav_col1:
|
|
@@ -495,7 +494,7 @@ with nav_col2:
|
|
| 495 |
set_page("analisis_batch"); st.rerun()
|
| 496 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 497 |
|
| 498 |
-
|
| 499 |
if st.session_state.page == "uji_kalimat":
|
| 500 |
st.markdown("""
|
| 501 |
<style>
|
|
@@ -533,7 +532,7 @@ def load_all_models():
|
|
| 533 |
roberta_large = pipeline("sentiment-analysis", model="siebert/sentiment-roberta-large-english", device=-1, truncation=True, max_length=512)
|
| 534 |
return vader, bertweet, roberta, roberta_large
|
| 535 |
|
| 536 |
-
with st.spinner('...'):
|
| 537 |
vader, bertweet, roberta, roberta_large = load_all_models()
|
| 538 |
|
| 539 |
|
|
@@ -572,7 +571,7 @@ def get_daily_label(score):
|
|
| 572 |
# ==============================================================================
|
| 573 |
if st.session_state.page == "uji_kalimat":
|
| 574 |
|
| 575 |
-
|
| 576 |
st.markdown('<div class="hero-wrap">', unsafe_allow_html=True)
|
| 577 |
|
| 578 |
col_text, col_img = st.columns([1.1, 1], gap="large")
|
|
@@ -617,7 +616,7 @@ if st.session_state.page == "uji_kalimat":
|
|
| 617 |
try:
|
| 618 |
st.image(img_hero, use_container_width=True)
|
| 619 |
except Exception:
|
| 620 |
-
|
| 621 |
st.markdown("""
|
| 622 |
<div style="background:rgba(255,255,255,0.1);border:2px dashed rgba(255,255,255,0.3);
|
| 623 |
border-radius:20px;height:320px;display:flex;align-items:center;
|
|
@@ -626,9 +625,9 @@ if st.session_state.page == "uji_kalimat":
|
|
| 626 |
πΌοΈ Tambahkan<br><code>crypto-currency-concept-830px.png</code><br>ke folder project
|
| 627 |
</div>""", unsafe_allow_html=True)
|
| 628 |
|
| 629 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 630 |
|
| 631 |
-
|
| 632 |
if analyze_btn:
|
| 633 |
st.markdown("""
|
| 634 |
<div class="result-wrap">
|
|
@@ -679,7 +678,7 @@ if st.session_state.page == "uji_kalimat":
|
|
| 679 |
("RoBERTa Large", rl_label),
|
| 680 |
]
|
| 681 |
|
| 682 |
-
|
| 683 |
st.markdown("<div style='padding: 0 3rem 3rem;'>", unsafe_allow_html=True)
|
| 684 |
col_a, col_b = st.columns(2)
|
| 685 |
|
|
@@ -724,17 +723,17 @@ elif st.session_state.page == "analisis_batch":
|
|
| 724 |
"grid.color": "#F1F5F9",
|
| 725 |
})
|
| 726 |
|
| 727 |
-
|
| 728 |
st.markdown('<div class="batch-wrap">', unsafe_allow_html=True)
|
| 729 |
|
| 730 |
col_upload, col_img_b = st.columns([1.4, 1], gap="large")
|
| 731 |
|
| 732 |
with col_upload:
|
| 733 |
st.markdown("""
|
| 734 |
-
<p class="batch-eyebrow">βοΈ Analisis Β· Batch Processing</p>
|
| 735 |
<h2 class="batch-title">Analisis Batch<br>Data Tweet</h2>
|
| 736 |
<p class="batch-sub">
|
| 737 |
-
Unggah file tweet (.txt) untuk diekstraksi dan
|
| 738 |
dianalisis secara masal terhadap volatilitas pasar Bitcoin.
|
| 739 |
</p>""", unsafe_allow_html=True)
|
| 740 |
|
|
@@ -769,9 +768,9 @@ elif st.session_state.page == "analisis_batch":
|
|
| 769 |
πΌοΈ Tambahkan<br><code>slice3-1-1536x830.png</code><br>ke folder project
|
| 770 |
</div>""", unsafe_allow_html=True)
|
| 771 |
|
| 772 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 773 |
|
| 774 |
-
|
| 775 |
if tweet_files and analyze_batch_btn:
|
| 776 |
st.markdown('<div class="result-wrap">', unsafe_allow_html=True)
|
| 777 |
st.markdown("""
|
|
@@ -883,7 +882,7 @@ elif st.session_state.page == "analisis_batch":
|
|
| 883 |
else:
|
| 884 |
st.markdown("<hr class='vbc-divider'>", unsafe_allow_html=True)
|
| 885 |
|
| 886 |
-
st.markdown("π£οΈ Data Sentimen Mentah")
|
| 887 |
raw_display_cols = ["date","raw_tweet","vader","textblob","bertweet","roberta","roberta_large"]
|
| 888 |
st.dataframe(df[raw_display_cols], use_container_width=True, hide_index=True)
|
| 889 |
|
|
@@ -903,12 +902,12 @@ elif st.session_state.page == "analisis_batch":
|
|
| 903 |
for col in models:
|
| 904 |
daily_display_cols.extend([col, f"{col}_label"])
|
| 905 |
|
| 906 |
-
st.markdown("βΏ
|
| 907 |
st.dataframe(df_price[["date","price","pct_change","log_return"]], use_container_width=True, hide_index=True)
|
| 908 |
|
| 909 |
df_merged = pd.merge(df_price, df_sentiment_daily, on="date", how="inner")
|
| 910 |
|
| 911 |
-
st.markdown("ποΈ Dataset Final (Terintegrasi)")
|
| 912 |
final_display_cols = ["date","price","pct_change","log_return"] + [c for c in daily_display_cols if c != "date"]
|
| 913 |
st.dataframe(df_merged[final_display_cols], use_container_width=True, hide_index=True)
|
| 914 |
|
|
@@ -954,7 +953,7 @@ elif st.session_state.page == "analisis_batch":
|
|
| 954 |
st.pyplot(fig_line)
|
| 955 |
|
| 956 |
# Scatter
|
| 957 |
-
st.markdown("π΅ Pola Distribusi Scatter")
|
| 958 |
cols = st.columns(3)
|
| 959 |
for idx2, method in enumerate(["vader","textblob","bertweet","roberta","roberta_large"]):
|
| 960 |
with cols[idx2 % 3]:
|
|
@@ -993,7 +992,8 @@ elif st.session_state.page == "analisis_batch":
|
|
| 993 |
**Hipotesis Ditolak (H0 Diterima):** Tidak ditemukan bukti empiris korelasi linier yang signifikan (seluruh *p-value* >= 0.05).
|
| 994 |
Volatilitas harga cenderung dipengaruhi oleh faktor teknikal/fundamental di luar sentimen X.
|
| 995 |
""")
|
| 996 |
-
|
|
|
|
| 997 |
|
| 998 |
elif analyze_batch_btn and not tweet_files:
|
| 999 |
-
st.warning("β οΈ Silakan unggah minimal satu file .txt terlebih dahulu.")
|
|
|
|
| 19 |
from langdetect import detect, DetectorFactory
|
| 20 |
DetectorFactory.seed = 0
|
| 21 |
|
|
|
|
| 22 |
# ==============================
|
| 23 |
+
# SETTING PATH ABSOLUT UNTUK GAMBAR
|
| 24 |
# ==============================
|
| 25 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 26 |
|
|
|
|
| 41 |
st.session_state.page = "uji_kalimat"
|
| 42 |
|
| 43 |
# ==============================
|
| 44 |
+
# GLOBAL CSS β Vancouver Bitcoin Style
|
| 45 |
# ==============================
|
| 46 |
st.markdown("""
|
| 47 |
<style>
|
|
|
|
| 461 |
|
| 462 |
|
| 463 |
# ==============================
|
| 464 |
+
# HEADER / NAVBAR β Vancouver Bitcoin style
|
| 465 |
# ==============================
|
| 466 |
def set_page(page_name):
|
| 467 |
st.session_state.page = page_name
|
|
|
|
| 475 |
</div>
|
| 476 |
""", unsafe_allow_html=True)
|
| 477 |
|
| 478 |
+
# Nav buttons sit just below navbar strip using columns
|
| 479 |
nav_col_pad, nav_col1, nav_col2, nav_col_end = st.columns([6, 1, 1, 1])
|
| 480 |
|
| 481 |
with nav_col1:
|
|
|
|
| 494 |
set_page("analisis_batch"); st.rerun()
|
| 495 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 496 |
|
| 497 |
+
# ββ Navbar overlay CSS (applies color context per page) ββ
|
| 498 |
if st.session_state.page == "uji_kalimat":
|
| 499 |
st.markdown("""
|
| 500 |
<style>
|
|
|
|
| 532 |
roberta_large = pipeline("sentiment-analysis", model="siebert/sentiment-roberta-large-english", device=-1, truncation=True, max_length=512)
|
| 533 |
return vader, bertweet, roberta, roberta_large
|
| 534 |
|
| 535 |
+
with st.spinner('Mempersiapkan model NLP...'):
|
| 536 |
vader, bertweet, roberta, roberta_large = load_all_models()
|
| 537 |
|
| 538 |
|
|
|
|
| 571 |
# ==============================================================================
|
| 572 |
if st.session_state.page == "uji_kalimat":
|
| 573 |
|
| 574 |
+
# ββ Hero section ββ
|
| 575 |
st.markdown('<div class="hero-wrap">', unsafe_allow_html=True)
|
| 576 |
|
| 577 |
col_text, col_img = st.columns([1.1, 1], gap="large")
|
|
|
|
| 616 |
try:
|
| 617 |
st.image(img_hero, use_container_width=True)
|
| 618 |
except Exception:
|
| 619 |
+
# Placeholder visual bila gambar belum ada
|
| 620 |
st.markdown("""
|
| 621 |
<div style="background:rgba(255,255,255,0.1);border:2px dashed rgba(255,255,255,0.3);
|
| 622 |
border-radius:20px;height:320px;display:flex;align-items:center;
|
|
|
|
| 625 |
πΌοΈ Tambahkan<br><code>crypto-currency-concept-830px.png</code><br>ke folder project
|
| 626 |
</div>""", unsafe_allow_html=True)
|
| 627 |
|
| 628 |
+
st.markdown('</div>', unsafe_allow_html=True) # close hero-wrap
|
| 629 |
|
| 630 |
+
# ββ Result section ββ
|
| 631 |
if analyze_btn:
|
| 632 |
st.markdown("""
|
| 633 |
<div class="result-wrap">
|
|
|
|
| 678 |
("RoBERTa Large", rl_label),
|
| 679 |
]
|
| 680 |
|
| 681 |
+
# Show as styled cards in 2 columns (2+2+1)
|
| 682 |
st.markdown("<div style='padding: 0 3rem 3rem;'>", unsafe_allow_html=True)
|
| 683 |
col_a, col_b = st.columns(2)
|
| 684 |
|
|
|
|
| 723 |
"grid.color": "#F1F5F9",
|
| 724 |
})
|
| 725 |
|
| 726 |
+
# ββ Batch hero section ββ
|
| 727 |
st.markdown('<div class="batch-wrap">', unsafe_allow_html=True)
|
| 728 |
|
| 729 |
col_upload, col_img_b = st.columns([1.4, 1], gap="large")
|
| 730 |
|
| 731 |
with col_upload:
|
| 732 |
st.markdown("""
|
| 733 |
+
<p class="batch-eyebrow">βοΈ Analisis Masal Β· Batch Processing</p>
|
| 734 |
<h2 class="batch-title">Analisis Batch<br>Data Tweet</h2>
|
| 735 |
<p class="batch-sub">
|
| 736 |
+
Unggah file rekam jejak tweet (.txt) untuk diekstraksi dan
|
| 737 |
dianalisis secara masal terhadap volatilitas pasar Bitcoin.
|
| 738 |
</p>""", unsafe_allow_html=True)
|
| 739 |
|
|
|
|
| 768 |
πΌοΈ Tambahkan<br><code>slice3-1-1536x830.png</code><br>ke folder project
|
| 769 |
</div>""", unsafe_allow_html=True)
|
| 770 |
|
| 771 |
+
st.markdown('</div>', unsafe_allow_html=True) # close batch-wrap
|
| 772 |
|
| 773 |
+
# ββ Processing & results ββ
|
| 774 |
if tweet_files and analyze_batch_btn:
|
| 775 |
st.markdown('<div class="result-wrap">', unsafe_allow_html=True)
|
| 776 |
st.markdown("""
|
|
|
|
| 882 |
else:
|
| 883 |
st.markdown("<hr class='vbc-divider'>", unsafe_allow_html=True)
|
| 884 |
|
| 885 |
+
st.markdown("#### π£οΈ Data Sentimen Mentah")
|
| 886 |
raw_display_cols = ["date","raw_tweet","vader","textblob","bertweet","roberta","roberta_large"]
|
| 887 |
st.dataframe(df[raw_display_cols], use_container_width=True, hide_index=True)
|
| 888 |
|
|
|
|
| 902 |
for col in models:
|
| 903 |
daily_display_cols.extend([col, f"{col}_label"])
|
| 904 |
|
| 905 |
+
st.markdown("#### βΏ Historis Harga & Volatilitas Bitcoin")
|
| 906 |
st.dataframe(df_price[["date","price","pct_change","log_return"]], use_container_width=True, hide_index=True)
|
| 907 |
|
| 908 |
df_merged = pd.merge(df_price, df_sentiment_daily, on="date", how="inner")
|
| 909 |
|
| 910 |
+
st.markdown("### ποΈ Dataset Final (Terintegrasi)")
|
| 911 |
final_display_cols = ["date","price","pct_change","log_return"] + [c for c in daily_display_cols if c != "date"]
|
| 912 |
st.dataframe(df_merged[final_display_cols], use_container_width=True, hide_index=True)
|
| 913 |
|
|
|
|
| 953 |
st.pyplot(fig_line)
|
| 954 |
|
| 955 |
# Scatter
|
| 956 |
+
st.markdown("### π΅ Pola Distribusi Scatter")
|
| 957 |
cols = st.columns(3)
|
| 958 |
for idx2, method in enumerate(["vader","textblob","bertweet","roberta","roberta_large"]):
|
| 959 |
with cols[idx2 % 3]:
|
|
|
|
| 992 |
**Hipotesis Ditolak (H0 Diterima):** Tidak ditemukan bukti empiris korelasi linier yang signifikan (seluruh *p-value* >= 0.05).
|
| 993 |
Volatilitas harga cenderung dipengaruhi oleh faktor teknikal/fundamental di luar sentimen X.
|
| 994 |
""")
|
| 995 |
+
|
| 996 |
+
st.markdown('</div>', unsafe_allow_html=True) # close result-wrap
|
| 997 |
|
| 998 |
elif analyze_batch_btn and not tweet_files:
|
| 999 |
+
st.warning("β οΈ Silakan unggah minimal satu file .txt terlebih dahulu.")
|