import streamlit as st import pandas as pd import numpy as np import os from grobidmonkey import reader def save_uploaded_file(uploaded_file): file_path = os.path.join("./uploads", uploaded_file.name) os.makedirs("./uploads", exist_ok=True) # Create 'uploads' directory if it doesn't exist with open(file_path, "wb") as f: f.write(uploaded_file.getbuffer()) return file_path # Return the file path as a string st.title('Paper2Slides') st.subheader('Upload paper in pdf format') col1, col2 = st.columns([3, 1]) with col1: uploaded_file = st.file_uploader("Choose a file") with col2: option = st.selectbox( 'Select parsing method.', ('monkey', 'x2d', 'lxml')) if uploaded_file is not None: st.write(uploaded_file.name) bytes_data = uploaded_file.getvalue() st.write(len(bytes_data), "bytes") saved_file_path = save_uploaded_file(uploaded_file) monkeyReader = reader.MonkeyReader(option) outline = monkeyReader.readOutline(saved_file_path) for pre, fill, node in outline: st.write("%s%s" % (pre, node.name)) # read paper content essay = monkeyReader.readEssay(saved_file_path) for key, values in essay.items(): st.write(f"{key}: {', '.join(values)}")