# Import libraries
import streamlit as st
import pandas as pd
import html
from weasyprint import HTML, CSS
import io
from datetime import datetime
#===config===
st.set_page_config(
page_title="TXTperpus",
page_icon="https://github.com/faizhalas/Search4All/blob/main/images/logo.png?raw=true",
layout="wide"
)
# Connect to the Google Sheet
st.cache_resource(ttl=3600*3)
def connect_gsheet():
sheet_id = st.secrets.sheet_id
sheet_name = st.secrets.sheet_journal
url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
df = pd.read_csv(url, dtype=str, header=0)
df = df.sort_index(ascending=False).fillna('NaN')
df["Full-text"] = df[["Abstract (en)", "Introduction", "Method", "Result & Discussion", "Conclusion"]].agg(" - ".join, axis=1)
return df
df = connect_gsheet()
def format_html(text):
return html.escape(text).replace("\n", "
")
st.title('TXTperpus: Reader')
paramx = st.query_params["art"]
filtered_df = df[df['ID'] == paramx]
st.write("Nomor artikel:", paramx)
opt_result = ["Baca Artikel", "Analisis Artikel"]
selection = st.pills("Pilihan", opt_result, selection_mode="single", default="Baca Artikel", label_visibility="hidden")
#tab1, tab2 = st.tabs(["📄 Baca Artikel", "📊 Analisis Artikel"])
filtered_df = filtered_df.replace("NaN", "Tidak tersedia")
row = filtered_df.iloc[0]
# Get and clean values
title = format_html(row.get("Title", ""))
author = format_html(row.get("Authors", ""))
intro = format_html(row.get("Introduction", ""))
method = format_html(row.get("Method", ""))
abstracten = format_html(row.get("Abstract (en)", ""))
abstractid = format_html(row.get("Abstract (id)", ""))
keywords = format_html(row.get("Keywords", ""))
affiliation = format_html(row.get("Institution", ""))
result = format_html(row.get("Result", ""))
discussion = format_html(row.get("Discussion", ""))
rnd = format_html(row.get("Result & Discussion", ""))
conclusion = format_html(row.get("Conclusion", ""))
if selection == "Baca Artikel":
with st.sidebar:
st.write("Atur Tampilan")
font_options = ["Baskerville", "Cambria", "Charter", "Garamond", "Georgia", "Palatino Linotype", "Times New Roman"]
font_selected = st.selectbox("Gaya kata", font_options)
fontsize = st.number_input("Ukuran kata", min_value=5, value=16, step=1)
no_columns = st.number_input("Jumlah kolom", min_value=1, max_value=4, value=1, step=1)
if not filtered_df.empty:
# CSS styles for individual sections (no container)
html_output = f"""