File size: 4,010 Bytes
4f7f1a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
from app import get_pdf_text
from app import get_text_chunks
from app import get_vector_store
from app import user_input
from paper_reading import get_pdf_files
from paper_reading import get_txt_from_pdf
from paper_reading import model_2



def mof_synthesis_processing(df):
    """Placeholder for MOF synthesis processing - replace with actual implementation"""
    # This is a simplified placeholder - you'll need to implement the actual processing
    st.warning("Full MOF processing implementation needed")
    return model_2(df)

def main():
    st.set_page_config("Multi-Functional PDF Tool")
    
    # Sidebar for mode selection
    app_mode = st.sidebar.selectbox("Choose Application Mode", 
                                    ["Chat with PDF", "MOF Synthesis Paper Processing"])
    
    if app_mode == "Chat with PDF":
        st.header("Chat with PDF using Groq and HuggingFace Embeddings💁")
        
        user_question = st.text_input("Ask a Question from the PDF Files")

        if user_question:
            user_input(user_question)

        with st.sidebar:
            st.title("Upload PDFs:")
            pdf_docs = st.file_uploader("Upload your PDF Files", accept_multiple_files=True)
            if st.button("Submit & Process"):
                with st.spinner("Processing..."):
                    raw_text = get_pdf_text(pdf_docs)
                    text_chunks = get_text_chunks(raw_text)
                    get_vector_store(text_chunks)
                    st.success("PDFs Processed Successfully")
    
    elif app_mode == "MOF Synthesis Paper Processing":
        st.title("MOF Synthesis Paper Processing")
        
        # Folder input for PDF processing
        folder = st.text_input("Enter the full path to the folder containing PDF files")
        
        if folder:
            try:
                folder_path = get_pdf_files(folder)
                
                if st.button("Process MOF Synthesis Papers"):
                    with st.spinner("Extracting text from PDFs..."):
                        # Extract text from PDFs
                        pdf_dataframe = get_txt_from_pdf(folder_path)
                    
                    if not pdf_dataframe.empty:
                        st.write(f"Extracted text from {len(pdf_dataframe['file name'].unique())} PDFs")
                        st.write(f"Total pages processed: {len(pdf_dataframe)}")
                        
                        # Process MOF synthesis papers
                        with st.spinner("Analyzing MOF Synthesis Papers..."):
                            processed_df = mof_synthesis_processing(pdf_dataframe)
                            
                            if not processed_df.empty:
                                # Display results
                                st.success("MOF Synthesis Papers Processed Successfully!")
                                
                                # Option to download processed data
                                csv = processed_df.to_csv(index=False)
                                st.download_button(
                                    label="Download Processed Data",
                                    data=csv,
                                    file_name="mof_synthesis_data.csv",
                                    mime="text/csv"
                                )
                                
                                # Display first few rows
                                st.dataframe(processed_df)
                            else:
                                st.warning("No MOF synthesis data was extracted.")
                    
                    else:
                        st.error("No PDFs found or error in extracting text")
            
            except Exception as e:
                st.error(f"An error occurred: {e}")

if __name__ == "__main__":
    main()