faizhalas commited on
Commit
f65bfcf
·
verified ·
1 Parent(s): eff9e3e

Update pages/reader.py

Browse files
Files changed (1) hide show
  1. pages/reader.py +64 -57
pages/reader.py CHANGED
@@ -1,6 +1,7 @@
1
  # Import libraries
2
  import streamlit as st
3
  import pandas as pd
 
4
 
5
 
6
  #===config===
@@ -24,6 +25,9 @@ def connect_gsheet():
24
 
25
  df = connect_gsheet()
26
 
 
 
 
27
  st.title('TXTperpus: Reader')
28
 
29
  paramx = st.query_params["art"]
@@ -33,60 +37,63 @@ filtered_df = df[df['ID'] == paramx]
33
 
34
  import html
35
 
36
- if not filtered_df.empty:
37
- row = filtered_df.iloc[0]
38
-
39
- title = html.escape(row["Title"])
40
- author = html.escape(row.get("Author", "Unknown Author"))
41
- intro = html.escape(row["Introduction"])
42
- method = html.escape(row["Method"])
43
-
44
- html_content = f"""
45
- <style>
46
- .article-container {{
47
- font-family: 'Georgia', serif;
48
- font-size: 16px;
49
- line-height: 1.8;
50
- color: #333;
51
- padding: 20px;
52
- background-color: #fefefe;
53
- border-radius: 10px;
54
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
55
- }}
56
- .article-title {{
57
- font-size: 28px;
58
- font-weight: bold;
59
- margin-bottom: 5px;
60
- }}
61
- .article-author {{
62
- font-size: 16px;
63
- color: #666;
64
- margin-bottom: 20px;
65
- }}
66
- .section-title {{
67
- font-size: 20px;
68
- font-weight: bold;
69
- margin-top: 25px;
70
- margin-bottom: 10px;
71
- color: #004488;
72
- }}
73
- .section-content {{
74
- text-align: justify;
75
- }}
76
- </style>
77
-
78
- <div class="article-container">
79
- <div class="article-title">{title}</div>
80
- <div class="article-author">By {author}</div>
81
-
82
- <div class="section-title">Introduction</div>
83
- <div class="section-content">{intro}</div>
84
-
85
- <div class="section-title">Method</div>
86
- <div class="section-content">{method}</div>
87
- </div>
88
- """
89
-
90
- st.markdown(html_content, unsafe_allow_html=True)
91
- else:
92
- st.warning("No matching article found.")
 
 
 
 
1
  # Import libraries
2
  import streamlit as st
3
  import pandas as pd
4
+ import html
5
 
6
 
7
  #===config===
 
25
 
26
  df = connect_gsheet()
27
 
28
+ def format_html(text):
29
+ return html.escape(text).replace("\n", "<br>")
30
+
31
  st.title('TXTperpus: Reader')
32
 
33
  paramx = st.query_params["art"]
 
37
 
38
  import html
39
 
40
+ row = {
41
+ "Title": "Sample Title <with tags>",
42
+ "Author": "John Doe",
43
+ "Introduction": "This is an introduction\nwith multiple lines.",
44
+ "Method": "This is the method section.\nIt includes steps."
45
+ }
46
+
47
+ title = format_html(row["Title"])
48
+ author = format_html(row["Author"])
49
+ intro = format_html(row["Introduction"])
50
+ method = format_html(row["Method"])
51
+
52
+ html_content = f"""
53
+ <style>
54
+ .article-container {{
55
+ font-family: 'Georgia', serif;
56
+ font-size: 16px;
57
+ line-height: 1.8;
58
+ color: #333;
59
+ padding: 20px;
60
+ background-color: #fefefe;
61
+ border-radius: 10px;
62
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
63
+ }}
64
+ .article-title {{
65
+ font-size: 28px;
66
+ font-weight: bold;
67
+ margin-bottom: 5px;
68
+ }}
69
+ .article-author {{
70
+ font-size: 16px;
71
+ color: #666;
72
+ margin-bottom: 20px;
73
+ }}
74
+ .section-title {{
75
+ font-size: 20px;
76
+ font-weight: bold;
77
+ margin-top: 25px;
78
+ margin-bottom: 10px;
79
+ color: #004488;
80
+ }}
81
+ .section-content {{
82
+ text-align: justify;
83
+ }}
84
+ </style>
85
+
86
+ <div class="article-container">
87
+ <div class="article-title">{title}</div>
88
+ <div class="article-author">By {author}</div>
89
+
90
+ <div class="section-title">Introduction</div>
91
+ <div class="section-content">{intro}</div>
92
+
93
+ <div class="section-title">Method</div>
94
+ <div class="section-content">{method}</div>
95
+ </div>
96
+ """
97
+
98
+ # Streamlit usage
99
+ st.markdown(html_content, unsafe_allow_html=True)