Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from pptx import Presentation
|
3 |
+
import io
|
4 |
+
|
5 |
+
def read_pptx(file):
|
6 |
+
"""
|
7 |
+
Reads a PowerPoint file and extracts text from slides.
|
8 |
+
"""
|
9 |
+
prs = Presentation(file)
|
10 |
+
text_content = []
|
11 |
+
for i, slide in enumerate(prs.slides):
|
12 |
+
slide_text = f"--- Slide {i+1} ---\n"
|
13 |
+
for shape in slide.shapes:
|
14 |
+
if hasattr(shape, "text"):
|
15 |
+
slide_text += shape.text + "\n"
|
16 |
+
text_content.append(slide_text)
|
17 |
+
return "\n".join(text_content)
|
18 |
+
|
19 |
+
st.title("PowerPoint Slide Reader")
|
20 |
+
|
21 |
+
uploaded_file = st.file_uploader("Choose a PowerPoint file (.pptx)", type=["pptx"])
|
22 |
+
|
23 |
+
if uploaded_file is not None:
|
24 |
+
st.success("File uploaded successfully!")
|
25 |
+
|
26 |
+
# To read the file as bytes, which python-pptx expects
|
27 |
+
bytes_data = uploaded_file.getvalue()
|
28 |
+
|
29 |
+
# Create a BytesIO object from the bytes data
|
30 |
+
# This allows python-pptx to read the file from memory
|
31 |
+
pptx_file_like = io.BytesIO(bytes_data)
|
32 |
+
|
33 |
+
try:
|
34 |
+
slide_text = read_pptx(pptx_file_like)
|
35 |
+
st.subheader("Extracted Text Content:")
|
36 |
+
st.text_area("Slide Content", slide_text, height=500)
|
37 |
+
|
38 |
+
except Exception as e:
|
39 |
+
st.error(f"Error processing PowerPoint file: {e}")
|
40 |
+
st.info("Please ensure it's a valid .pptx file.")
|