Update app.py
Browse files123411 unmodified lines16171819202167 unmodified lines8990919293949596979899100101102import ioimport osimport jsonimport gradio as gr11 unmodified lineshuggingface_token = os.environ.get("HUGGINGFACE_TOKEN")def load_and_split_document(file):"""Loads and splits the document into pages."""loader = PyPDFLoader(file.name)67 unmodified linesdata = [{"page_content": doc.page_content, "metadata": json.dumps(doc.metadata)} for doc in documents]df = pd.DataFrame(data)# Save DataFrame to an in-memory Excel fileoutput = io.BytesIO()with pd.ExcelWriter(output, engine='openpyxl') as writer:df.to_excel(writer, index=False)output.seek(0)# Return the file data in a format Gradio can handlereturn (output.getvalue(), "database_output.xlsx")# Modify the Gradio interfacewith gr.Blocks() as demo:123411 unmodified lines16171819202122232467 unmodified lines9293949596979899100101102103import tempfileimport osimport jsonimport gradio as gr11 unmodified lineshuggingface_token = os.environ.get("HUGGINGFACE_TOKEN")# At the beginning of your scriptos.environ['TMPDIR'] = '/tmp'def load_and_split_document(file):"""Loads and splits the document into pages."""loader = PyPDFLoader(file.name)67 unmodified linesdata = [{"page_content": doc.page_content, "metadata": json.dumps(doc.metadata)} for doc in documents]df = pd.DataFrame(data)# Create a temporary filewith tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx') as tmp:excel_path = tmp.namedf.to_excel(excel_path, index=False)return excel_path# Modify the Gradio interfacewith gr.Blocks() as demo:
app.py+9-8