To upload files, please first save the app
# fifapp.py
import streamlit as st
import sqlite3
from PyPDF2 import PdfReader
# Désactiver le file watcher de Streamlit
st.set_option("server.enableCORS", False)
st.set_option("server.enableXsrfProtection", False)
st.set_option("server.enableWebsocketCompression", False)
st.set_option("server.fileWatcherType", "none")
# Configuration de la base de données en mémoire
DB_NAME = "file:pdfdb?mode=memory&cache=shared"
def init_db():
conn = sqlite3.connect(DB_NAME, uri=True)
conn.execute('''CREATE TABLE IF NOT EXISTS pdf_chunks
(id INTEGER PRIMARY KEY,
page INTEGER,
chunk TEXT)''')
conn.commit()
return conn
def process_pdf(file):
conn = init_db()
pdf = PdfReader(file)
for page_num, page in enumerate(pdf.pages):
if text := page.extract_text():
# Découpage simplifié
chunks = [text[i:i+1000] for i in range(0, len(text), 800)]
for chunk_num, chunk in enumerate(chunks):
conn.execute("INSERT INTO pdf_chunks (page, chunk) VALUES (?, ?)",
(page_num+1, chunk.strip()))
conn.commit()
return len(pdf.pages), len(chunks)
# Interface optimisée
def main():
st.title("📄 PDF Processor")
st.write("Version compatible Pyodide")
if file := st.file_uploader("Upload PDF", type="pdf"):
with st.spinner("Analyse..."):
pages, chunks = process_pdf(file)
st.success(f"Pages: {pages} | Segments: {chunks}")
# Affichage direct sans pandas
preview = sqlite3.connect(DB_NAME, uri=True).execute(
"SELECT page, chunk FROM pdf_chunks LIMIT 3"
).fetchall()
st.write("Preview:")
for p, c in preview:
st.write(f"**Page {p}:** {c[:100]}...")
if __name__ == "__main__":
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?