import streamlit as st import subprocess import camelot # Function to install dependencies def install_dependencies(): try: import plotly except ImportError: st.write("Installing plotly...") subprocess.check_call(["pip", "install", "plotly", "camelot-py[cv]"]) st.write("plotly installed successfully.") # Install other dependencies if needed required_libraries = ["torch", "transformers", "pdfplumber", "camelot-py[cv]", "pandas"] for library in required_libraries: try: __import__(library) except ImportError: st.write(f"Installing {library}...") subprocess.check_call(["pip", "install", library]) st.write(f"{library} installed successfully.") # Install dependencies install_dependencies() # Title and Description st.title("Automated Datasheet Summarizer with Table Parsing") st.write("Upload a datasheet PDF or enter a component name to get simplified summaries, key specs, and visual insights.") # Input Options input_type = st.radio("Select Input Type:", ["Upload PDF", "Enter Component Name"]) if input_type == "Upload PDF": uploaded_file = st.file_uploader("Upload a Datasheet PDF", type=["pdf"]) if uploaded_file is not None: try: # Parse tables using Camelot tables = camelot.read_pdf(uploaded_file, pages="all") if len(tables) > 0: for i, table in enumerate(tables): st.write(f"Table {i+1}") st.dataframe(table.df) else: st.warning("No tables found in the PDF.") except Exception as e: st.error(f"Error parsing tables with Camelot: {e}") elif input_type == "Enter Component Name": component_name = st.text_input("Enter Component Name") if component_name and st.button("Search and Summarize"): st.error("Component search functionality is under development.") # Footer st.markdown("---") st.markdown("**Note:** This tool is in beta. Accuracy of the generated summaries and parsed tables depends on the quality of the datasheet.")