To upload files, please first save the app
# app.py
import streamlit as st
from PyPDF2 import PdfReader
import json
def process_pdf(file):
"""Traitement PDF entièrement en mémoire"""
pdf = PdfReader(file)
text = " ".join(page.extract_text() or "" for page in pdf.pages)
return [text[i:i+500] for i in range(0, len(text), 300)]
def main():
# Configuration minimale pour désactiver les fonctionnalités problématiques
st._config.set_option("server.enableCORS", False)
st._config.set_option("server.enableXsrfProtection", False)
st.title("PDF Quiz Generator")
if pdf_file := st.file_uploader("Upload PDF"):
chunks = process_pdf(pdf_file)
if chunk := st.selectbox("Select content", chunks, format_func=lambda x: x[:50] + "..."):
if st.button("Generate"):
quiz = {
"question": f"About: {chunk[:100]}...",
"options": ["True", "False"],
"answer": 0
}
st.download_button("Download", json.dumps(quiz), "quiz.json")
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?