Spaces:
No application file
No application file
Download main.py from Aaryan1314/Bot1: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/Aaryan1314/Bot1/resolve/main/main.py
- Command line
-
hf download hf://spaces/Aaryan1314/Bot1/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Aaryan1314/Bot1/resolve/main/main.py
1.04 kB
| prompt = ChatPromptTemplate.from_template(custom_prompt_template) | |
| chain = prompt | model | |
| return chain.invoke({"question": query, "context": context}) | |
| uploaded_file = st.file_uploader( | |
| "Upload PDF", | |
| type="pdf", | |
| accept_multiple_files=False | |
| ) | |
| user_query = st.text_area("Enter your prompt: ", height=150 , placeholder= "Ask Anything!") | |
| ask_question = st.button("Ask AI Lawyer") | |
| if ask_question: | |
| if uploaded_file and user_query: | |
| upload_pdf(uploaded_file) | |
| documents = load_pdf(pdfs_directory + uploaded_file.name) | |
| text_chunks = create_chunks(documents) | |
| faiss_db = create_vector_store(FAISS_DB_PATH, text_chunks, ollama_model_name) | |
| retrieved_docs=retrieve_docs(faiss_db, user_query) | |
| response=answer_query(documents=retrieved_docs, model=llm_model, query=user_query) | |
| st.chat_message("user").write(user_query) | |
| st.chat_message("AI Lawyer").write(response) | |
| else: | |
| st.error("Kindly upload a valid PDF file and/or ask a valid Question!") |