Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,10 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
| 6 |
from langchain import OpenAI, VectorDBQA
|
| 7 |
|
| 8 |
import os
|
| 9 |
-
openai_api_key = "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"
|
| 10 |
-
os.environ["OPENAI_API_KEY"] = openai_api_key
|
| 11 |
|
| 12 |
-
def pdf_to_text(pdf_file, query):
|
|
|
|
|
|
|
| 13 |
# Open the PDF file in binary mode
|
| 14 |
with open(pdf_file.name, 'rb') as pdf_file:
|
| 15 |
# Create a PDF reader object
|
|
@@ -28,7 +28,7 @@ def pdf_to_text(pdf_file, query):
|
|
| 28 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 29 |
texts = text_splitter.split_text(text)
|
| 30 |
|
| 31 |
-
embeddings = OpenAIEmbeddings(openai_api_key=
|
| 32 |
#vector store
|
| 33 |
vectorstore = FAISS.from_texts(texts, embeddings)
|
| 34 |
|
|
@@ -40,7 +40,7 @@ def pdf_to_text(pdf_file, query):
|
|
| 40 |
pdf_input = gr.inputs.File(label="PDF File")
|
| 41 |
query_input = gr.inputs.Textbox(label="Query")
|
| 42 |
outputs = gr.outputs.Textbox(label="Chatbot Response")
|
| 43 |
-
interface = gr.Interface(fn=pdf_to_text, inputs=[pdf_input, query_input], outputs=outputs)
|
| 44 |
|
| 45 |
# Run the interface
|
| 46 |
interface.launch(debug = True)
|
|
|
|
| 6 |
from langchain import OpenAI, VectorDBQA
|
| 7 |
|
| 8 |
import os
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def pdf_to_text(pdf_file, contraseña, query):
|
| 11 |
+
os.environ["OPENAI_API_KEY"] = contraseña
|
| 12 |
+
|
| 13 |
# Open the PDF file in binary mode
|
| 14 |
with open(pdf_file.name, 'rb') as pdf_file:
|
| 15 |
# Create a PDF reader object
|
|
|
|
| 28 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 29 |
texts = text_splitter.split_text(text)
|
| 30 |
|
| 31 |
+
embeddings = OpenAIEmbeddings(openai_api_key=contraseña)
|
| 32 |
#vector store
|
| 33 |
vectorstore = FAISS.from_texts(texts, embeddings)
|
| 34 |
|
|
|
|
| 40 |
pdf_input = gr.inputs.File(label="PDF File")
|
| 41 |
query_input = gr.inputs.Textbox(label="Query")
|
| 42 |
outputs = gr.outputs.Textbox(label="Chatbot Response")
|
| 43 |
+
interface = gr.Interface(fn=pdf_to_text, inputs=[pdf_input, gr.Textbox(lines=1, placeholder="Enter your API-key here...", label="API-Key:", type="password"), query_input], outputs=outputs)
|
| 44 |
|
| 45 |
# Run the interface
|
| 46 |
interface.launch(debug = True)
|