Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -287,95 +287,61 @@ def display_articles():
|
|
287 |
# Sort files by name for consistent ordering
|
288 |
html_files.sort()
|
289 |
|
290 |
-
st.markdown("Click on any article below to
|
291 |
-
st.markdown("
|
292 |
|
293 |
-
# Display each article as a clickable
|
294 |
-
for html_file in html_files:
|
295 |
# Extract filename without path and extension, format it nicely
|
296 |
file_name = os.path.splitext(os.path.basename(html_file))[0]
|
297 |
display_name = file_name.replace('_', ' ').replace('-', ' ').title()
|
298 |
|
299 |
-
#
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
# Add a JavaScript link that opens in new tab (alternative method)
|
308 |
-
st.markdown(f"""
|
309 |
-
<a href="file://{os.path.abspath(html_file)}" target="_blank" style="text-decoration: none;">
|
310 |
-
<div style="padding: 10px; border: 1px solid #ddd; border-radius: 5px; margin: 5px 0; background-color: #f9f9f9; cursor: pointer;">
|
311 |
-
📄 {display_name}
|
312 |
-
</div>
|
313 |
-
</a>
|
314 |
-
""", unsafe_allow_html=True)
|
315 |
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
except:
|
323 |
-
st.text("- KB")
|
324 |
|
325 |
-
|
326 |
-
# Add download button for each file
|
327 |
try:
|
328 |
with open(html_file, 'r', encoding='utf-8') as file:
|
329 |
html_content = file.read()
|
330 |
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
except Exception as e:
|
339 |
-
st.
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
st.info("💡 **Alternative Method**: If the links above don't work, select an article below to view it inline:")
|
344 |
-
|
345 |
-
# Fallback option with selectbox
|
346 |
-
file_options = [os.path.splitext(os.path.basename(f))[0].replace('_', ' ').title() for f in html_files]
|
347 |
-
|
348 |
-
selected_idx = st.selectbox(
|
349 |
-
"Choose an article to view inline:",
|
350 |
-
options=range(len(html_files)),
|
351 |
-
format_func=lambda x: file_options[x],
|
352 |
-
key="inline_article_selector"
|
353 |
-
)
|
354 |
-
|
355 |
-
if st.button("Open Selected Article in New Tab"):
|
356 |
-
selected_file = html_files[selected_idx]
|
357 |
-
|
358 |
-
# Create a temporary serving method using Streamlit's built-in server
|
359 |
-
try:
|
360 |
-
with open(selected_file, 'r', encoding='utf-8') as file:
|
361 |
-
html_content = file.read()
|
362 |
-
|
363 |
-
# Use JavaScript to open content in new window (safer approach)
|
364 |
-
js_code = """
|
365 |
-
<script>
|
366 |
-
function openArticle() {
|
367 |
-
var newWindow = window.open();
|
368 |
-
var content = """ + repr(html_content) + """;
|
369 |
-
newWindow.document.write(content);
|
370 |
-
newWindow.document.close();
|
371 |
-
}
|
372 |
-
openArticle();
|
373 |
-
</script>
|
374 |
-
"""
|
375 |
-
st.markdown(js_code, unsafe_allow_html=True)
|
376 |
-
|
377 |
-
except Exception as e:
|
378 |
-
st.error(f"Error opening article: {str(e)}")
|
379 |
|
380 |
def display_apps():
|
381 |
st.markdown('## Apps')
|
|
|
287 |
# Sort files by name for consistent ordering
|
288 |
html_files.sort()
|
289 |
|
290 |
+
st.markdown("Click on any article below to view:")
|
291 |
+
st.markdown("") # Add some space
|
292 |
|
293 |
+
# Display each article as a clean clickable card
|
294 |
+
for i, html_file in enumerate(html_files):
|
295 |
# Extract filename without path and extension, format it nicely
|
296 |
file_name = os.path.splitext(os.path.basename(html_file))[0]
|
297 |
display_name = file_name.replace('_', ' ').replace('-', ' ').title()
|
298 |
|
299 |
+
# Get file size
|
300 |
+
try:
|
301 |
+
file_size = os.path.getsize(html_file)
|
302 |
+
size_kb = round(file_size / 1024, 1)
|
303 |
+
size_text = f"{size_kb} KB"
|
304 |
+
except:
|
305 |
+
size_text = "- KB"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
+
# Create a clean card-like button
|
308 |
+
article_clicked = st.button(
|
309 |
+
f"📄 {display_name} ({size_text})",
|
310 |
+
key=f"article_{i}",
|
311 |
+
use_container_width=True
|
312 |
+
)
|
|
|
|
|
313 |
|
314 |
+
if article_clicked:
|
|
|
315 |
try:
|
316 |
with open(html_file, 'r', encoding='utf-8') as file:
|
317 |
html_content = file.read()
|
318 |
|
319 |
+
# Display article content inline
|
320 |
+
st.markdown("---")
|
321 |
+
st.markdown(f"### {display_name}")
|
322 |
+
|
323 |
+
# Add download option
|
324 |
+
col1, col2 = st.columns([1, 4])
|
325 |
+
with col1:
|
326 |
+
st.download_button(
|
327 |
+
label="⬇️ Download",
|
328 |
+
data=html_content,
|
329 |
+
file_name=os.path.basename(html_file),
|
330 |
+
mime="text/html",
|
331 |
+
key=f"download_clicked_{i}"
|
332 |
+
)
|
333 |
+
with col2:
|
334 |
+
if st.button("❌ Close Article", key=f"close_{i}"):
|
335 |
+
st.rerun()
|
336 |
+
|
337 |
+
# Display the HTML content
|
338 |
+
st.components.v1.html(html_content, height=600, scrolling=True)
|
339 |
+
|
340 |
except Exception as e:
|
341 |
+
st.error(f"Error loading article: {str(e)}")
|
342 |
+
|
343 |
+
# Add small spacing between articles
|
344 |
+
st.markdown("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
def display_apps():
|
347 |
st.markdown('## Apps')
|