File size: 6,267 Bytes
bcbe27e f65bfcf 351fada 79ad351 7ad8eeb bcbe27e c87e24f bcbe27e f65bfcf 4e60c40 bcbe27e a988a2e bcbe27e 0748879 6387629 0748879 bb4c1b2 6387629 0d32192 e0c48c5 6387629 0d32192 4e60c40 d4ec5e7 0d32192 e0c48c5 0d32192 d4ec5e7 0e61ae8 f0f7314 0e61ae8 f0f7314 bcba0db f0f7314 bcba0db 0d32192 6387629 0d32192 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# 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", "<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")
#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"""
<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 with dynamic timestamp
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;
}}
}}
""")
# Generate PDF once
pdf_file = io.BytesIO()
HTML(string=html_output).write_pdf(pdf_file, stylesheets=[css])
pdf_file.seek(0)
# Show download button in sidebar
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") |