Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,12 @@ import streamlit as st
|
|
| 2 |
from PyPDF2 import PdfReader
|
| 3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 4 |
import os
|
| 5 |
-
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 6 |
import google.generativeai as genai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from langchain.vectorstores import FAISS
|
| 8 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 9 |
from langchain.chains.question_answering import load_qa_chain
|
|
@@ -15,10 +19,6 @@ os.getenv("GOOGLE_API_KEY")
|
|
| 15 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 16 |
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
def get_pdf_text(pdf_docs):
|
| 23 |
text=""
|
| 24 |
for pdf in pdf_docs:
|
|
@@ -48,10 +48,12 @@ def get_conversational_chain():
|
|
| 48 |
provided context just say, "answer is not available in the context", don't provide the wrong answer\n\n
|
| 49 |
Context:\n {context}?\n
|
| 50 |
Question: \n{question}\n
|
|
|
|
| 51 |
Answer:
|
| 52 |
"""
|
| 53 |
|
| 54 |
-
model = ChatGoogleGenerativeAI(model="gemini-pro",
|
|
|
|
| 55 |
|
| 56 |
prompt = PromptTemplate(template = prompt_template, input_variables = ["context", "question"])
|
| 57 |
chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
|
|
@@ -80,10 +82,10 @@ def user_input(user_question):
|
|
| 80 |
|
| 81 |
|
| 82 |
def main():
|
| 83 |
-
st.set_page_config("
|
| 84 |
-
st.header("Chat with PDF
|
| 85 |
|
| 86 |
-
user_question = st.text_input("Ask a Question from the
|
| 87 |
|
| 88 |
if user_question:
|
| 89 |
user_input(user_question)
|
|
|
|
| 2 |
from PyPDF2 import PdfReader
|
| 3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 4 |
import os
|
|
|
|
| 5 |
import google.generativeai as genai
|
| 6 |
+
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 7 |
+
from langchain_google_genai import GoogleGenerativeAI
|
| 8 |
+
from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
|
| 9 |
+
from langchain_google_genai.embeddings import GoogleGenerativeAIEmbeddings
|
| 10 |
+
from langchain_google_genai.llms import GoogleGenerativeAI
|
| 11 |
from langchain.vectorstores import FAISS
|
| 12 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 13 |
from langchain.chains.question_answering import load_qa_chain
|
|
|
|
| 19 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def get_pdf_text(pdf_docs):
|
| 23 |
text=""
|
| 24 |
for pdf in pdf_docs:
|
|
|
|
| 48 |
provided context just say, "answer is not available in the context", don't provide the wrong answer\n\n
|
| 49 |
Context:\n {context}?\n
|
| 50 |
Question: \n{question}\n
|
| 51 |
+
|
| 52 |
Answer:
|
| 53 |
"""
|
| 54 |
|
| 55 |
+
model = ChatGoogleGenerativeAI(model="gemini-pro",
|
| 56 |
+
temperature=0.3)
|
| 57 |
|
| 58 |
prompt = PromptTemplate(template = prompt_template, input_variables = ["context", "question"])
|
| 59 |
chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
def main():
|
| 85 |
+
st.set_page_config("Chat PDF")
|
| 86 |
+
st.header("Chat with PDF 💁")
|
| 87 |
|
| 88 |
+
user_question = st.text_input("Ask a Question from the PDF Files")
|
| 89 |
|
| 90 |
if user_question:
|
| 91 |
user_input(user_question)
|