|
|
|
|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import html |
|
|
from weasyprint import HTML, CSS |
|
|
import io |
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config( |
|
|
page_title="TXTperpus", |
|
|
page_icon="https://github.com/faizhalas/Search4All/blob/main/images/logo.png?raw=true", |
|
|
layout="wide" |
|
|
) |
|
|
|
|
|
|
|
|
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", "<br>") |
|
|
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|
|
|
filtered_df = filtered_df.replace("NaN", "Tidak tersedia") |
|
|
row = filtered_df.iloc[0] |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
|
|
|
html_output = f""" |
|
|
<style> |
|
|
.article-title {{ |
|
|
text-align: center; |
|
|
font-size: 28px; |
|
|
font-weight: bold; |
|
|
font-family: {font_selected}, serif; |
|
|
color: #222; |
|
|
margin-bottom: 5px; |
|
|
}} |
|
|
.article-author {{ |
|
|
text-align: center; |
|
|
font-size: 16px; |
|
|
color: #666; |
|
|
margin-bottom: 20px; |
|
|
font-style: italic; |
|
|
}} |
|
|
.section-title {{ |
|
|
text-align: center; |
|
|
font-size: 20px; |
|
|
font-weight: bold; |
|
|
margin-top: 25px; |
|
|
margin-bottom: 10px; |
|
|
color: #004488; |
|
|
}} |
|
|
.section-meta {{ |
|
|
text-align: center; |
|
|
font-size: {fontsize}px; |
|
|
font-family: {font_selected}, serif; |
|
|
line-height: 1.8; |
|
|
color: #333; |
|
|
font-style: italic; |
|
|
}} |
|
|
.section-content {{ |
|
|
column-count: {no_columns}; |
|
|
column-gap: 40px; |
|
|
text-align: justify; |
|
|
font-size: {fontsize}px; |
|
|
font-family: {font_selected}, serif; |
|
|
line-height: 1.8; |
|
|
color: #333; |
|
|
}} |
|
|
</style> |
|
|
|
|
|
<div class="article-title">{title}</div> |
|
|
<div class="article-author">By {author}</div> |
|
|
<div class="article-author">{affiliation}</div> |
|
|
|
|
|
<div class="section-title">Abstract</div> |
|
|
<div class="section-meta">{abstracten}</div> |
|
|
<div class="section-title">Abstrak</div> |
|
|
<div class="section-meta">{abstractid}</div> |
|
|
<div class="article-author">Keywords: {keywords}</div> |
|
|
|
|
|
<div class="section-title">Introduction</div> |
|
|
<div class="section-content">{intro}</div> |
|
|
|
|
|
<div class="section-title">Method</div> |
|
|
<div class="section-content">{method}</div> |
|
|
|
|
|
<div class="section-title">Result</div> |
|
|
<div class="section-content">{result}</div> |
|
|
|
|
|
<div class="section-title">Discussion</div> |
|
|
<div class="section-content">{discussion}</div> |
|
|
|
|
|
<div class="section-title">Result & Discussion</div> |
|
|
<div class="section-content">{rnd}</div> |
|
|
|
|
|
<div class="section-title">Conclusion</div> |
|
|
<div class="section-content">{conclusion}</div> |
|
|
""" |
|
|
|
|
|
st.markdown(html_output, unsafe_allow_html=True) |
|
|
|
|
|
now_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
|
|
|
|
|
css = CSS(string=f""" |
|
|
@page {{ |
|
|
size: A4; |
|
|
margin: 2cm; |
|
|
|
|
|
@top-center {{ |
|
|
content: "Tulisan ini mungkin ada beberapa tidak tepat. Diunduh pada {now_str}"; |
|
|
font-size: 11px; |
|
|
color: #444; |
|
|
}} |
|
|
|
|
|
@bottom-center {{ |
|
|
content: "Page " counter(page) " of " counter(pages); |
|
|
font-size: 11px; |
|
|
color: #666; |
|
|
}} |
|
|
}} |
|
|
""") |
|
|
|
|
|
|
|
|
pdf_file = io.BytesIO() |
|
|
HTML(string=html_output).write_pdf(pdf_file, stylesheets=[css]) |
|
|
pdf_file.seek(0) |
|
|
|
|
|
|
|
|
st.sidebar.download_button( |
|
|
label="๐ Unduh PDF", |
|
|
data=pdf_file, |
|
|
file_name="article.pdf", |
|
|
mime="application/pdf" |
|
|
) |
|
|
|
|
|
else: |
|
|
st.warning("No article found with the specified ID.") |
|
|
|
|
|
else: |
|
|
st.write("Dalam pembangunan") |