mabuseif commited on
Commit
11946a9
·
verified ·
1 Parent(s): ea6bf79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -30
app.py CHANGED
@@ -104,6 +104,11 @@ def load_css():
104
  border-radius: 4px;
105
  overflow: hidden;
106
  }
 
 
 
 
 
107
  </style>
108
  """, unsafe_allow_html=True)
109
 
@@ -117,9 +122,6 @@ def format_citation_html(url, fragment_text, author, year, scc_hash):
117
  full_url = f"{url}#:~:text={encoded_fragment}"
118
  return f'<a href="{full_url}" data-hash="{scc_hash}">{author}, {year}</a>'
119
 
120
- def check_for_fragment(url):
121
- return '#:~:text=' in url
122
-
123
  def copy_to_clipboard_js(text, button_id):
124
  """Generate JavaScript for copying text to clipboard"""
125
  return f"""
@@ -214,9 +216,13 @@ with st.expander("About SCC and Example Citation"):
214
  - URL: <code>https://www.sciencedirect.com/science/article/pii/S2772411523000046</code><br>
215
  - Text: <code>A proposed design framework for green roof settings in general and trees on buildings</code><br>
216
 
217
- <strong>Output (HTML):</strong><br>
218
- <div class="hash-display">
219
- &lt;a href="https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=A%20proposed%20design%20framework%20for%20green%20roof%20settings%20in%20general%20and%20trees%20on%20buildings" data-hash="[GENERATED_HASH]"&gt;Abuseif et al., 2025&lt;/a&gt;
 
 
 
 
220
  </div>
221
  </div>
222
  """, unsafe_allow_html=True)
@@ -274,27 +280,28 @@ with tabs[0]:
274
  """, unsafe_allow_html=True)
275
  else:
276
  scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
 
277
 
278
  st.markdown("## Generated Citations")
279
  col_html1, col_html2 = st.columns(2)
280
 
281
  # HTML Citation - Start of Text
282
  with col_html1:
283
- st.markdown("### HTML Citation (Start of Text)")
284
- html_citation_start = f'"{annotated_text}" (<a href="{source_url}#:~:text={urllib.parse.quote(annotated_text)}" data-hash="{scc_hash}">{author_name}, {publication_year}</a>)'
285
 
286
- st.markdown('<div class="citation-output">', unsafe_allow_html=True)
287
- st.code(html_citation_start, language='html')
288
  st.markdown(copy_to_clipboard_js(html_citation_start.replace('`', '\\`'), "html_start"), unsafe_allow_html=True)
289
  st.markdown('</div>', unsafe_allow_html=True)
290
 
291
  # HTML Citation - End of Text
292
  with col_html2:
293
- st.markdown("### HTML Citation (End of Text)")
294
- html_citation_end = f'(<a href="{source_url}#:~:text={urllib.parse.quote(annotated_text)}" data-hash="{scc_hash}">{author_name}, {publication_year}</a>) "{annotated_text}"'
295
 
296
- st.markdown('<div class="citation-output">', unsafe_allow_html=True)
297
- st.code(html_citation_end, language='html')
298
  st.markdown(copy_to_clipboard_js(html_citation_end.replace('`', '\\`'), "html_end"), unsafe_allow_html=True)
299
  st.markdown('</div>', unsafe_allow_html=True)
300
 
@@ -317,22 +324,7 @@ with tabs[0]:
317
  st.json(hash_details)
318
  st.markdown('</div>', unsafe_allow_html=True)
319
 
320
- # Instructions section
321
- st.markdown("## Instructions for Copying to Word")
322
- st.markdown("""
323
- <div class="info-card">
324
- <strong>To use the generated HTML citation in Microsoft Word:</strong><br><br>
325
- 1. Copy the desired HTML citation (Start or End of Text) using the 'Copy to Clipboard' button<br>
326
- 2. In Word, go to the 'Insert' tab<br>
327
- 3. Click on 'Object' → 'Text from File...'<br>
328
- 4. Select 'HTML Document' from the file type dropdown<br>
329
- 5. Paste the copied HTML into a new text file (e.g., using Notepad) and save it with a <code>.html</code> extension<br>
330
- 6. Select this <code>.html</code> file in the 'Text from File...' dialog<br><br>
331
-
332
- <strong>Alternative method:</strong> You might be able to paste directly into Word and then right-click and choose 'Keep Source Formatting' or 'Merge Formatting' if available, but the 'Text from File' method is more reliable for preserving hyperlinks and data attributes.
333
- </div>
334
- """, unsafe_allow_html=True)
335
-
336
  st.markdown("## Guidance on Verifying Citations")
337
  st.markdown("""
338
  <div class="info-card">
 
104
  border-radius: 4px;
105
  overflow: hidden;
106
  }
107
+
108
+ .rendered-citation {
109
+ margin: 1rem 0;
110
+ font-size: 1rem;
111
+ }
112
  </style>
113
  """, unsafe_allow_html=True)
114
 
 
122
  full_url = f"{url}#:~:text={encoded_fragment}"
123
  return f'<a href="{full_url}" data-hash="{scc_hash}">{author}, {year}</a>'
124
 
 
 
 
125
  def copy_to_clipboard_js(text, button_id):
126
  """Generate JavaScript for copying text to clipboard"""
127
  return f"""
 
216
  - URL: <code>https://www.sciencedirect.com/science/article/pii/S2772411523000046</code><br>
217
  - Text: <code>A proposed design framework for green roof settings in general and trees on buildings</code><br>
218
 
219
+ <strong>Output (Start of Text):</strong><br>
220
+ <div class="rendered-citation">
221
+ Abuseif et al. (2025) A proposed design framework for green roof settings in general and trees on buildings
222
+ </div>
223
+ <strong>Output (End of Text):</strong><br>
224
+ <div class="rendered-citation">
225
+ (Abuseif et al., 2025) A proposed design framework for green roof settings in general and trees on buildings
226
  </div>
227
  </div>
228
  """, unsafe_allow_html=True)
 
280
  """, unsafe_allow_html=True)
281
  else:
282
  scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
283
+ citation_link = format_citation_html(source_url, annotated_text, author_name, publication_year, scc_hash)
284
 
285
  st.markdown("## Generated Citations")
286
  col_html1, col_html2 = st.columns(2)
287
 
288
  # HTML Citation - Start of Text
289
  with col_html1:
290
+ st.markdown("### Citation (Start of Text)")
291
+ html_citation_start = f'{citation_link} {annotated_text}'
292
 
293
+ st.markdown('<div class="rendered-citation">', unsafe_allow_html=True)
294
+ st.markdown(html_citation_start, unsafe_allow_html=True)
295
  st.markdown(copy_to_clipboard_js(html_citation_start.replace('`', '\\`'), "html_start"), unsafe_allow_html=True)
296
  st.markdown('</div>', unsafe_allow_html=True)
297
 
298
  # HTML Citation - End of Text
299
  with col_html2:
300
+ st.markdown("### Citation (End of Text)")
301
+ html_citation_end = f'({citation_link}) {annotated_text}'
302
 
303
+ st.markdown('<div class="rendered-citation">', unsafe_allow_html=True)
304
+ st.markdown(html_citation_end, unsafe_allow_html=True)
305
  st.markdown(copy_to_clipboard_js(html_citation_end.replace('`', '\\`'), "html_end"), unsafe_allow_html=True)
306
  st.markdown('</div>', unsafe_allow_html=True)
307
 
 
324
  st.json(hash_details)
325
  st.markdown('</div>', unsafe_allow_html=True)
326
 
327
+ # Guidance on Verifying Citations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  st.markdown("## Guidance on Verifying Citations")
329
  st.markdown("""
330
  <div class="info-card">