Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from datasets import load_dataset
|
3 |
import pandas as pd
|
4 |
-
import math
|
5 |
|
6 |
# Fungsi untuk membaca data dari Hugging Face dataset
|
7 |
@st.cache_resource
|
@@ -13,43 +12,29 @@ def load_data():
|
|
13 |
# Fungsi untuk menampilkan card
|
14 |
def display_card(article_name, journal_name, article_url):
|
15 |
return f"""
|
16 |
-
<div
|
17 |
-
<h5
|
18 |
-
<p
|
19 |
<a href="{article_url}" target="_blank">
|
20 |
-
<button
|
21 |
-
Kunjungi Artikel
|
22 |
-
</button>
|
23 |
</a>
|
24 |
</div>
|
25 |
"""
|
26 |
|
27 |
-
# Fungsi untuk menampilkan data dalam
|
28 |
-
def display_data(data, start_index, end_index
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
col_end = min(col_start + items_per_column, end_index)
|
36 |
-
|
37 |
-
for i in range(col_start, col_end):
|
38 |
-
article_name = data.iloc[i]['article_name']
|
39 |
-
journal_name = data.iloc[i]['journal_name']
|
40 |
-
article_url = data.iloc[i]['article_url']
|
41 |
-
cols[col_index].markdown(display_card(article_name, journal_name, article_url), unsafe_allow_html=True)
|
42 |
-
|
43 |
-
else:
|
44 |
-
cols = st.columns(3) # Buat 3 kolom
|
45 |
-
for i in range(start_index, end_index):
|
46 |
article_name = data.iloc[i]['article_name']
|
47 |
journal_name = data.iloc[i]['journal_name']
|
48 |
article_url = data.iloc[i]['article_url']
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
cols[col_index].markdown(display_card(article_name, journal_name, article_url), unsafe_allow_html=True)
|
53 |
|
54 |
# Fungsi untuk menambah data yang ditampilkan
|
55 |
def show_more():
|
@@ -57,43 +42,65 @@ def show_more():
|
|
57 |
|
58 |
# Main app
|
59 |
def main():
|
60 |
-
st.set_page_config(page_title="ID CS Journal Aggregator", layout="wide")
|
61 |
-
|
62 |
-
#
|
63 |
st.markdown("""
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
""", unsafe_allow_html=True)
|
73 |
|
74 |
-
# Get the screen width from JavaScript
|
75 |
-
is_mobile = st.query_params.get("is_mobile", ["false"])[0] == "true"
|
76 |
-
st.write(is_mobile)
|
77 |
-
|
78 |
# Judul terpusat
|
79 |
st.markdown("<h1 style='text-align: center;'>Indonesian Computer Science<br>Journal Aggregator</h1>", unsafe_allow_html=True)
|
80 |
-
|
81 |
# Load data dari Hugging Face dataset
|
82 |
data = load_data()
|
83 |
-
|
84 |
# Inisialisasi jumlah data yang ditampilkan
|
85 |
if 'num_displayed' not in st.session_state:
|
86 |
st.session_state.num_displayed = 18 # Jumlah card yang ditampilkan awalnya
|
87 |
-
|
88 |
# Tampilkan data
|
89 |
end_index = min(st.session_state.num_displayed, len(data))
|
90 |
-
display_data(data, 0, end_index
|
91 |
-
|
92 |
# Tombol "Show More"
|
93 |
-
if st.session_state.num_displayed < len(data):
|
94 |
-
if is_mobile:
|
95 |
-
st.button("Show More", on_click=show_more, key="show_more", use_container_width=True)
|
96 |
-
else:
|
97 |
col1, col2, col3 = st.columns([1,2,1])
|
98 |
with col2:
|
99 |
st.button("Show More", on_click=show_more, key="show_more", use_container_width=True)
|
|
|
1 |
import streamlit as st
|
2 |
from datasets import load_dataset
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
# Fungsi untuk membaca data dari Hugging Face dataset
|
6 |
@st.cache_resource
|
|
|
12 |
# Fungsi untuk menampilkan card
|
13 |
def display_card(article_name, journal_name, article_url):
|
14 |
return f"""
|
15 |
+
<div class="card">
|
16 |
+
<h5>{article_name}</h5>
|
17 |
+
<p>{journal_name}</p>
|
18 |
<a href="{article_url}" target="_blank">
|
19 |
+
<button>Kunjungi Artikel</button>
|
|
|
|
|
20 |
</a>
|
21 |
</div>
|
22 |
"""
|
23 |
|
24 |
+
# Fungsi untuk menampilkan data dalam grid responsif
|
25 |
+
def display_data(data, start_index, end_index):
|
26 |
+
st.markdown("""
|
27 |
+
<div class="grid-container">
|
28 |
+
""", unsafe_allow_html=True)
|
29 |
+
|
30 |
+
for i in range(start_index, end_index):
|
31 |
+
if i < len(data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
article_name = data.iloc[i]['article_name']
|
33 |
journal_name = data.iloc[i]['journal_name']
|
34 |
article_url = data.iloc[i]['article_url']
|
35 |
+
st.markdown(display_card(article_name, journal_name, article_url), unsafe_allow_html=True)
|
36 |
+
|
37 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
38 |
|
39 |
# Fungsi untuk menambah data yang ditampilkan
|
40 |
def show_more():
|
|
|
42 |
|
43 |
# Main app
|
44 |
def main():
|
45 |
+
st.set_page_config(page_title="ID CS Journal Aggregator", layout="wide")
|
46 |
+
|
47 |
+
# CSS untuk tata letak responsif
|
48 |
st.markdown("""
|
49 |
+
<style>
|
50 |
+
.grid-container {
|
51 |
+
display: flex;
|
52 |
+
flex-wrap: wrap;
|
53 |
+
gap: 15px;
|
54 |
+
justify-content: space-between;
|
55 |
+
}
|
56 |
+
.card {
|
57 |
+
flex: 0 1 calc(33.333% - 10px);
|
58 |
+
border: 1px solid #ccc;
|
59 |
+
padding: 20px;
|
60 |
+
border-radius: 5px;
|
61 |
+
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
|
62 |
+
text-align: justify;
|
63 |
+
}
|
64 |
+
.card h5 {
|
65 |
+
margin: 0;
|
66 |
+
font-size: 1.2em;
|
67 |
+
}
|
68 |
+
.card p {
|
69 |
+
margin: 5px 0;
|
70 |
+
}
|
71 |
+
.card button {
|
72 |
+
background-color: #4CAF50;
|
73 |
+
color: white;
|
74 |
+
border: none;
|
75 |
+
padding: 5px 9px;
|
76 |
+
margin-top: 5px;
|
77 |
+
border-radius: 5px;
|
78 |
+
font-size: 0.9em;
|
79 |
+
}
|
80 |
+
@media (max-width: 768px) {
|
81 |
+
.card {
|
82 |
+
flex: 0 1 100%;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
</style>
|
86 |
""", unsafe_allow_html=True)
|
87 |
|
|
|
|
|
|
|
|
|
88 |
# Judul terpusat
|
89 |
st.markdown("<h1 style='text-align: center;'>Indonesian Computer Science<br>Journal Aggregator</h1>", unsafe_allow_html=True)
|
90 |
+
|
91 |
# Load data dari Hugging Face dataset
|
92 |
data = load_data()
|
93 |
+
|
94 |
# Inisialisasi jumlah data yang ditampilkan
|
95 |
if 'num_displayed' not in st.session_state:
|
96 |
st.session_state.num_displayed = 18 # Jumlah card yang ditampilkan awalnya
|
97 |
+
|
98 |
# Tampilkan data
|
99 |
end_index = min(st.session_state.num_displayed, len(data))
|
100 |
+
display_data(data, 0, end_index)
|
101 |
+
|
102 |
# Tombol "Show More"
|
103 |
+
if st.session_state.num_displayed < len(data):
|
|
|
|
|
|
|
104 |
col1, col2, col3 = st.columns([1,2,1])
|
105 |
with col2:
|
106 |
st.button("Show More", on_click=show_more, key="show_more", use_container_width=True)
|