mabuseif commited on
Commit
e9cd3a9
·
verified ·
1 Parent(s): 723d07b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -47
app.py CHANGED
@@ -131,35 +131,24 @@ def parse_metadata_hash(metadata_html):
131
  def verification_js():
132
  return """
133
  <script>
134
- function updateCitationData() {
135
- const citationInput = document.getElementById('citation_input');
136
- const hashInput = document.getElementById('hash_input');
137
- const citationOutput = document.getElementById('citation_output');
138
- const hashOutput = document.getElementById('hash_output');
139
-
140
- if (citationInput && hashInput && citationOutput && hashOutput) {
141
- const citationLink = citationInput.querySelector('a');
142
- const hashLink = hashInput.querySelector('a');
143
-
144
- citationOutput.value = citationLink ? citationLink.outerHTML : '';
145
- hashOutput.value = hashLink ? hashLink.outerHTML : '';
146
-
147
- // Trigger form submission to update Streamlit
148
- if (citationLink || hashLink) {
149
- const form = document.getElementById('verify_form');
150
- if (form) {
151
- form.dispatchEvent(new Event('submit'));
152
- }
153
- }
154
  }
155
  }
156
 
157
  document.getElementById('citation_input').addEventListener('paste', function(e) {
158
- setTimeout(updateCitationData, 100);
159
  });
160
 
161
  document.getElementById('hash_input').addEventListener('paste', function(e) {
162
- setTimeout(updateCitationData, 100);
163
  });
164
  </script>
165
  """
@@ -340,24 +329,20 @@ with tabs[1]:
340
  </div>
341
  """, unsafe_allow_html=True)
342
 
343
- # Form to handle submission
344
- with st.form(key="verify_form"):
345
- st.markdown("""
346
- <div>
347
- <label>Paste Citation (with embedded link)</label>
348
- <div id="citation_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
349
- <input type="hidden" id="citation_output" name="citation_output">
350
- <label>Paste Hash (with embedded link)</label>
351
- <div id="hash_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
352
- <input type="hidden" id="hash_output" name="hash_output">
353
- </div>
354
- """, unsafe_allow_html=True)
355
-
356
- # Add JavaScript to capture pasted link data
357
- components.html(verification_js(), height=0)
358
-
359
- # Submit button for the form
360
- verify_button = st.form_submit_button("Verify Citation", type="primary", use_container_width=True)
361
 
362
  # Initialize session state
363
  if 'citation_html' not in st.session_state:
@@ -365,18 +350,26 @@ with tabs[1]:
365
  if 'hash_html' not in st.session_state:
366
  st.session_state.hash_html = ''
367
 
368
- # Update session state with form data
369
- if verify_button:
370
- citation_html = st.session_state.get('citation_output', '')
371
- hash_html = st.session_state.get('hash_output', '')
 
 
 
 
 
372
 
373
- if not (citation_html and hash_html):
 
 
 
374
  st.error("Please paste both the citation and hash links before verifying.")
375
  else:
376
  # Parse citation
377
- author, year, url, fragment_text, citation_hash = parse_citation(citation_html)
378
  # Parse hash and metadata
379
- scc_hash, username, task_name, date, time = parse_metadata_hash(hash_html)
380
 
381
  if not all([author, year, url, fragment_text, scc_hash, username, task_name, date, time]):
382
  st.error("Invalid citation or hash format. Please ensure both inputs are correctly pasted links from the generated output.")
 
131
  def verification_js():
132
  return """
133
  <script>
134
+ function updateCitationData(inputId, outputId) {
135
+ const input = document.getElementById(inputId);
136
+ const output = document.getElementById(outputId);
137
+ if (input && output) {
138
+ const link = input.querySelector('a');
139
+ output.value = link ? link.outerHTML : '';
140
+ // Dispatch input event to trigger Streamlit update
141
+ const event = new Event('input', { bubbles: true });
142
+ output.dispatchEvent(event);
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
  }
145
 
146
  document.getElementById('citation_input').addEventListener('paste', function(e) {
147
+ setTimeout(() => updateCitationData('citation_input', 'citation_output'), 100);
148
  });
149
 
150
  document.getElementById('hash_input').addEventListener('paste', function(e) {
151
+ setTimeout(() => updateCitationData('hash_input', 'hash_output'), 100);
152
  });
153
  </script>
154
  """
 
329
  </div>
330
  """, unsafe_allow_html=True)
331
 
332
+ # Input fields for citation and hash
333
+ st.markdown("""
334
+ <div>
335
+ <label>Paste Citation (with embedded link)</label>
336
+ <div id="citation_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
337
+ <input type="hidden" id="citation_output" name="citation_output" value="">
338
+ <label>Paste Hash (with embedded link)</label>
339
+ <div id="hash_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
340
+ <input type="hidden" id="hash_output" name="hash_output" value="">
341
+ </div>
342
+ """, unsafe_allow_html=True)
343
+
344
+ # Add JavaScript to capture pasted link data
345
+ components.html(verification_js(), height=0)
 
 
 
 
346
 
347
  # Initialize session state
348
  if 'citation_html' not in st.session_state:
 
350
  if 'hash_html' not in st.session_state:
351
  st.session_state.hash_html = ''
352
 
353
+ # Hidden text inputs to capture JavaScript data
354
+ citation_html = st.text_input("Citation HTML", key="citation_output", value=st.session_state.citation_html, label_visibility="collapsed")
355
+ hash_html = st.text_input("Hash HTML", key="hash_output", value=st.session_state.hash_html, label_visibility="collapsed")
356
+
357
+ # Update session state
358
+ if citation_html != st.session_state.citation_html:
359
+ st.session_state.citation_html = citation_html
360
+ if hash_html != st.session_state.hash_html:
361
+ st.session_state.hash_html = hash_html
362
 
363
+ verify_button = st.button("Verify Citation", type="primary", use_container_width=True)
364
+
365
+ if verify_button:
366
+ if not (st.session_state.citation_html and st.session_state.hash_html):
367
  st.error("Please paste both the citation and hash links before verifying.")
368
  else:
369
  # Parse citation
370
+ author, year, url, fragment_text, citation_hash = parse_citation(st.session_state.citation_html)
371
  # Parse hash and metadata
372
+ scc_hash, username, task_name, date, time = parse_metadata_hash(st.session_state.hash_html)
373
 
374
  if not all([author, year, url, fragment_text, scc_hash, username, task_name, date, time]):
375
  st.error("Invalid citation or hash format. Please ensure both inputs are correctly pasted links from the generated output.")