Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +146 -13
src/app.py
CHANGED
|
@@ -1,3 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
from langchain_groq import ChatGroq
|
|
@@ -52,26 +193,18 @@ st.sidebar.title("Upload your pdf")
|
|
| 52 |
|
| 53 |
main_placeholder = st.empty()
|
| 54 |
#Document upload
|
| 55 |
-
uploaded_file = st.sidebar.file_uploader("_____________________________________", type="pdf")
|
| 56 |
st.sidebar.write("Press Submit to process:")
|
| 57 |
process = st.sidebar.button("Submit")
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
# if process:
|
| 61 |
-
# if uploaded_file:
|
| 62 |
-
# # Process the uploaded PDF file
|
| 63 |
-
# process_pdf(uploaded_file)
|
| 64 |
-
# else:
|
| 65 |
-
# st.warning("Please upload a PDF file.")
|
| 66 |
-
|
| 67 |
if process:
|
| 68 |
-
if uploaded_file
|
| 69 |
-
|
| 70 |
-
process_pdf(
|
| 71 |
else:
|
| 72 |
st.warning("Please upload a PDF file.")
|
| 73 |
|
| 74 |
-
|
| 75 |
if input_method == "Choose input method...":
|
| 76 |
st.title(f"Welcome You all!")
|
| 77 |
st.title("Choose an option in the sidebar")
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# import os
|
| 3 |
+
# from langchain_groq import ChatGroq
|
| 4 |
+
# from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 5 |
+
# from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 6 |
+
# from langchain_core.prompts import ChatPromptTemplate
|
| 7 |
+
# from langchain.chains import create_retrieval_chain
|
| 8 |
+
# from langchain_community.vectorstores import FAISS
|
| 9 |
+
# from langchain_community.document_loaders import PyPDFDirectoryLoader
|
| 10 |
+
# from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 11 |
+
# from dotenv import load_dotenv
|
| 12 |
+
# from PDFprocess_sample import process_pdf
|
| 13 |
+
|
| 14 |
+
# # Loading GROQ and Google API
|
| 15 |
+
# load_dotenv()
|
| 16 |
+
|
| 17 |
+
# GROQ_API_KEY = os.getenv('GROQ_API_KEY')
|
| 18 |
+
# os.environ["GOOGLE_API_KEY"]= os.getenv('GOOGLE_API_KEY')
|
| 19 |
+
|
| 20 |
+
# #Loading CSS files
|
| 21 |
+
|
| 22 |
+
# def load_css(file_name):
|
| 23 |
+
# with open(file_name) as f:
|
| 24 |
+
# css = f.read()
|
| 25 |
+
# st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
|
| 26 |
+
|
| 27 |
+
# load_css('CSS/style.css')
|
| 28 |
+
|
| 29 |
+
# #setting up LLM
|
| 30 |
+
# llm = ChatGroq(
|
| 31 |
+
# api_key=GROQ_API_KEY,
|
| 32 |
+
# model_name="Llama3-8b-8192"
|
| 33 |
+
# )
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# prompt = ChatPromptTemplate.from_template(
|
| 37 |
+
# """
|
| 38 |
+
# Answer the questions based on the provided context only.
|
| 39 |
+
# Please provide the most accurate response based on the question. Try to answer in detail in 1500 words
|
| 40 |
+
# <context>
|
| 41 |
+
# {context}
|
| 42 |
+
# <context>
|
| 43 |
+
# Questions: {input}
|
| 44 |
+
# """
|
| 45 |
+
# )
|
| 46 |
+
|
| 47 |
+
# input_method = st.sidebar.selectbox("Choose a method" , ["Choose input method...","Interact with Doc", "Get Ques from Doc"])
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# st.sidebar.title("Upload your pdf")
|
| 52 |
+
|
| 53 |
+
# main_placeholder = st.empty()
|
| 54 |
+
# #Document upload
|
| 55 |
+
# uploaded_file = st.sidebar.file_uploader("_____________________________________", type="pdf")
|
| 56 |
+
# st.sidebar.write("Press Submit to process:")
|
| 57 |
+
# process = st.sidebar.button("Submit")
|
| 58 |
+
|
| 59 |
+
# # Document processing to convert it into vectors
|
| 60 |
+
# # if process:
|
| 61 |
+
# # if uploaded_file:
|
| 62 |
+
# # # Process the uploaded PDF file
|
| 63 |
+
# # process_pdf(uploaded_file)
|
| 64 |
+
# # else:
|
| 65 |
+
# # st.warning("Please upload a PDF file.")
|
| 66 |
+
|
| 67 |
+
# if process:
|
| 68 |
+
# if uploaded_file is not None:
|
| 69 |
+
# file_bytes = uploaded_file.read()
|
| 70 |
+
# process_pdf(file_bytes)
|
| 71 |
+
# else:
|
| 72 |
+
# st.warning("Please upload a PDF file.")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# if input_method == "Choose input method...":
|
| 76 |
+
# st.title(f"Welcome You all!")
|
| 77 |
+
# st.title("Choose an option in the sidebar")
|
| 78 |
+
# st.title("Now, let's get started!")
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# #If User wants to interact with the document
|
| 82 |
+
# elif input_method == "Interact with Doc":
|
| 83 |
+
# st.title(f"let's Interact with pdf's")
|
| 84 |
+
|
| 85 |
+
# prompt1 = st.text_input("______", placeholder="Enter your Question")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# # Generate response if question is entered
|
| 89 |
+
# if prompt1 and "vectors" in st.session_state:
|
| 90 |
+
# document_chain = create_stuff_documents_chain(llm, prompt)
|
| 91 |
+
# retriever = st.session_state.vectors.as_retriever()
|
| 92 |
+
# retrieval_chain = create_retrieval_chain(retriever, document_chain)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# response = retrieval_chain.invoke({'input': prompt1})
|
| 96 |
+
|
| 97 |
+
# # st.write(response['answer'])
|
| 98 |
+
|
| 99 |
+
# #Get the respose in the card
|
| 100 |
+
# st.markdown(
|
| 101 |
+
# f"""
|
| 102 |
+
# <div class="card">
|
| 103 |
+
# <div class="response">{response['answer']}</div>
|
| 104 |
+
# </div>
|
| 105 |
+
# """,
|
| 106 |
+
# unsafe_allow_html=True,
|
| 107 |
+
# )
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# #When User wants to get questions from the doc based on certain topic
|
| 112 |
+
# elif input_method == "Get Ques from Doc":
|
| 113 |
+
# st.title(f"Let's Get Ques from Document")
|
| 114 |
+
|
| 115 |
+
# prompt2 = """Based on the topic of {topic},
|
| 116 |
+
# kindly provide a comprehensive list of all possible questions that could arise.
|
| 117 |
+
# For each question, provide detailed and explanatory answers in atleast 1000 words detail based on the context,
|
| 118 |
+
# ensuring that the responses are as informative as possible.
|
| 119 |
+
# make sure you strictly follow the {topic}"""
|
| 120 |
+
# topic = st.text_input("Enter a topic", placeholder="What is your topic")
|
| 121 |
+
|
| 122 |
+
# # Generate response if question is entered
|
| 123 |
+
# if topic and "vectors" in st.session_state:
|
| 124 |
+
# document_chain = create_stuff_documents_chain(llm, prompt)
|
| 125 |
+
# retriever = st.session_state.vectors.as_retriever()
|
| 126 |
+
# retrieval_chain = create_retrieval_chain(retriever, document_chain)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
# response = retrieval_chain.invoke({'input': prompt2})
|
| 130 |
+
|
| 131 |
+
# #Get the respose in the card
|
| 132 |
+
# st.markdown(
|
| 133 |
+
# f"""
|
| 134 |
+
# <div class="card">
|
| 135 |
+
# <div class="response">{response['answer']}</div>
|
| 136 |
+
# </div>
|
| 137 |
+
# """,
|
| 138 |
+
# unsafe_allow_html=True,
|
| 139 |
+
# )
|
| 140 |
+
|
| 141 |
+
|
| 142 |
import streamlit as st
|
| 143 |
import os
|
| 144 |
from langchain_groq import ChatGroq
|
|
|
|
| 193 |
|
| 194 |
main_placeholder = st.empty()
|
| 195 |
#Document upload
|
| 196 |
+
uploaded_file = st.sidebar.file_uploader("_____________________________________", type="pdf", accept_multiple_files=True)
|
| 197 |
st.sidebar.write("Press Submit to process:")
|
| 198 |
process = st.sidebar.button("Submit")
|
| 199 |
|
| 200 |
+
#Document processing to convert it into vectors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
if process:
|
| 202 |
+
if uploaded_file:
|
| 203 |
+
# Process the uploaded PDF file
|
| 204 |
+
process_pdf(uploaded_file)
|
| 205 |
else:
|
| 206 |
st.warning("Please upload a PDF file.")
|
| 207 |
|
|
|
|
| 208 |
if input_method == "Choose input method...":
|
| 209 |
st.title(f"Welcome You all!")
|
| 210 |
st.title("Choose an option in the sidebar")
|