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