LazyHuman10 commited on
Commit Β·
e34605e
1
Parent(s): ca07346
Add Office preview support for Word and PowerPoint files
Browse files- Home.py +1 -1
- README.md +2 -2
- pages/Study_Material_Hub.py +25 -19
Home.py
CHANGED
|
@@ -76,7 +76,7 @@ step_cards = [
|
|
| 76 |
(
|
| 77 |
"02",
|
| 78 |
"Browse the material",
|
| 79 |
-
"Open notes and
|
| 80 |
),
|
| 81 |
(
|
| 82 |
"03",
|
|
|
|
| 76 |
(
|
| 77 |
"02",
|
| 78 |
"Browse the material",
|
| 79 |
+
"Open notes, Word docs, and slides in the hub and preview them without leaving the app.",
|
| 80 |
),
|
| 81 |
(
|
| 82 |
"03",
|
README.md
CHANGED
|
@@ -32,10 +32,10 @@ Plexi is a free web app that gives Collage students easy access to study materia
|
|
| 32 |
|
| 33 |
### Study Material Hub
|
| 34 |
|
| 35 |
-
Browse and download notes, slides, and other materials organized by **semester β subject β type**. PDFs open right in the browser β no extra apps needed.
|
| 36 |
|
| 37 |
- Filter by semester, subject, and file type
|
| 38 |
-
-
|
| 39 |
- Download any file with one click
|
| 40 |
|
| 41 |
### Plexi Assistant
|
|
|
|
| 32 |
|
| 33 |
### Study Material Hub
|
| 34 |
|
| 35 |
+
Browse and download notes, slides, and other materials organized by **semester β subject β type**. PDFs, Word documents, and PowerPoint files open right in the browser β no extra apps needed.
|
| 36 |
|
| 37 |
- Filter by semester, subject, and file type
|
| 38 |
+
- Inline preview for PDF, DOC, DOCX, PPT, and PPTX
|
| 39 |
- Download any file with one click
|
| 40 |
|
| 41 |
### Plexi Assistant
|
pages/Study_Material_Hub.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from html import escape
|
|
|
|
| 2 |
|
| 3 |
import streamlit as st
|
|
|
|
| 4 |
from streamlit_pdf_viewer import pdf_viewer
|
| 5 |
from utils import (
|
| 6 |
APP_ICON_PATH,
|
|
@@ -20,25 +22,29 @@ st.set_page_config(
|
|
| 20 |
)
|
| 21 |
inject_theme()
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def display_pdf(file_content):
|
| 25 |
"""Display PDF using streamlit-pdf-viewer."""
|
| 26 |
pdf_viewer(file_content, width="100%", height=700)
|
| 27 |
|
| 28 |
|
| 29 |
-
def
|
| 30 |
-
"""
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
use_container_width=True,
|
| 38 |
-
type="primary",
|
| 39 |
)
|
| 40 |
|
| 41 |
-
|
| 42 |
try:
|
| 43 |
manifest = get_manifest()
|
| 44 |
except Exception as err:
|
|
@@ -62,15 +68,16 @@ with st.container():
|
|
| 62 |
"Material hub",
|
| 63 |
"Browse the catalog without losing context",
|
| 64 |
(
|
| 65 |
-
"Move from semester to file in a single flow, preview
|
| 66 |
-
"download the exact asset you want from the shared materials
|
|
|
|
| 67 |
),
|
| 68 |
badges=[
|
| 69 |
f"{catalog_summary['semester_count']} semesters"
|
| 70 |
if catalog_summary
|
| 71 |
else None,
|
| 72 |
f"{catalog_summary['file_count']} files" if catalog_summary else None,
|
| 73 |
-
"Inline
|
| 74 |
],
|
| 75 |
)
|
| 76 |
|
|
@@ -182,11 +189,10 @@ with preview_col:
|
|
| 182 |
|
| 183 |
if file_mime == "application/pdf":
|
| 184 |
display_pdf(file_content)
|
| 185 |
-
elif file_mime in
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
display_ppt(file_content, selected_file_obj["name"])
|
| 190 |
else:
|
| 191 |
st.info(
|
| 192 |
"Preview is not available for this file type. Download it to inspect the content."
|
|
|
|
| 1 |
from html import escape
|
| 2 |
+
from urllib.parse import quote
|
| 3 |
|
| 4 |
import streamlit as st
|
| 5 |
+
import streamlit.components.v1 as components
|
| 6 |
from streamlit_pdf_viewer import pdf_viewer
|
| 7 |
from utils import (
|
| 8 |
APP_ICON_PATH,
|
|
|
|
| 22 |
)
|
| 23 |
inject_theme()
|
| 24 |
|
| 25 |
+
OFFICE_PREVIEW_MIMES = {
|
| 26 |
+
"application/msword",
|
| 27 |
+
"application/vnd.ms-powerpoint",
|
| 28 |
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
| 29 |
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
|
| 33 |
def display_pdf(file_content):
|
| 34 |
"""Display PDF using streamlit-pdf-viewer."""
|
| 35 |
pdf_viewer(file_content, width="100%", height=700)
|
| 36 |
|
| 37 |
|
| 38 |
+
def display_office_document(download_url, filename):
|
| 39 |
+
"""Display Word and PowerPoint files using Office Web Viewer."""
|
| 40 |
+
encoded_url = quote(download_url, safe="")
|
| 41 |
+
preview_url = f"https://view.officeapps.live.com/op/embed.aspx?src={encoded_url}"
|
| 42 |
+
components.iframe(preview_url, width=None, height=700, scrolling=True)
|
| 43 |
+
st.caption(
|
| 44 |
+
f"Inline preview for `{filename}` is powered by Office Web Viewer. "
|
| 45 |
+
"If it does not load, use the download button."
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
|
|
|
| 48 |
try:
|
| 49 |
manifest = get_manifest()
|
| 50 |
except Exception as err:
|
|
|
|
| 68 |
"Material hub",
|
| 69 |
"Browse the catalog without losing context",
|
| 70 |
(
|
| 71 |
+
"Move from semester to file in a single flow, preview supported files in "
|
| 72 |
+
"place, and download the exact asset you want from the shared materials "
|
| 73 |
+
"repository."
|
| 74 |
),
|
| 75 |
badges=[
|
| 76 |
f"{catalog_summary['semester_count']} semesters"
|
| 77 |
if catalog_summary
|
| 78 |
else None,
|
| 79 |
f"{catalog_summary['file_count']} files" if catalog_summary else None,
|
| 80 |
+
"Inline document preview",
|
| 81 |
],
|
| 82 |
)
|
| 83 |
|
|
|
|
| 189 |
|
| 190 |
if file_mime == "application/pdf":
|
| 191 |
display_pdf(file_content)
|
| 192 |
+
elif file_mime in OFFICE_PREVIEW_MIMES:
|
| 193 |
+
display_office_document(
|
| 194 |
+
selected_file_obj["download_url"], selected_file_obj["name"]
|
| 195 |
+
)
|
|
|
|
| 196 |
else:
|
| 197 |
st.info(
|
| 198 |
"Preview is not available for this file type. Download it to inspect the content."
|