damand2061 commited on
Commit
0bd316f
1 Parent(s): 180b43f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -66
app.py CHANGED
@@ -1,6 +1,7 @@
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,29 +13,29 @@ def load_data():
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,68 +43,26 @@ 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)
107
 
108
  if __name__ == "__main__":
109
- main()
 
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
  # Fungsi untuk menampilkan card
14
  def display_card(article_name, journal_name, article_url):
15
  return f"""
16
+ <div style="border:1px solid #ccc; padding: 20px; margin: 15px 0; border-radius: 5px; width: 100%; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1); text-align: justify;">
17
+ <h5 style="margin: 0; font-size: 1.2em;">{article_name}</h5>
18
+ <p style="margin: 5px 0; text-align: justify;">{journal_name}</p>
19
  <a href="{article_url}" target="_blank">
20
+ <button style="background-color: #4CAF50; color: white; border: none; padding: 5px 9px; margin-top: 5px; border-radius: 5px; font-size: 0.9em;">
21
+ Kunjungi Artikel
22
+ </button>
23
  </a>
24
  </div>
25
  """
26
 
27
+ # Fungsi untuk menampilkan data secara row-wise
28
  def display_data(data, start_index, end_index):
29
+ # Buat 3 kolom
30
+ for i in range(start_index, end_index, 3):
31
+ cols = st.columns(3) # Selalu buat 3 kolom
32
+ for j in range(3):
33
+ if i + j < end_index:
34
+ article_name = data.iloc[i + j]['article_name']
35
+ journal_name = data.iloc[i + j]['journal_name']
36
+ article_url = data.iloc[i + j]['article_url']
37
+ # Menampilkan setiap data di kolom yang sesuai
38
+ cols[j].markdown(display_card(article_name, journal_name, article_url), unsafe_allow_html=True)
 
 
39
 
40
  # Fungsi untuk menambah data yang ditampilkan
41
  def show_more():
 
43
 
44
  # Main app
45
  def main():
46
+ st.set_page_config(page_title="ID CS Journal Aggregator", layout="wide") # Set layout lebar
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # Judul terpusat
48
  st.markdown("<h1 style='text-align: center;'>Indonesian Computer Science<br>Journal Aggregator</h1>", unsafe_allow_html=True)
49
+
50
  # Load data dari Hugging Face dataset
51
  data = load_data()
52
+
53
  # Inisialisasi jumlah data yang ditampilkan
54
  if 'num_displayed' not in st.session_state:
55
  st.session_state.num_displayed = 18 # Jumlah card yang ditampilkan awalnya
56
+
57
  # Tampilkan data
58
  end_index = min(st.session_state.num_displayed, len(data))
59
  display_data(data, 0, end_index)
60
+
61
  # Tombol "Show More"
62
  if st.session_state.num_displayed < len(data):
63
+ col1, col2, col3 = st.columns([1, 2, 1])
64
  with col2:
65
  st.button("Show More", on_click=show_more, key="show_more", use_container_width=True)
66
 
67
  if __name__ == "__main__":
68
+ main()