Spaces:
Sleeping
Sleeping
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.") |