Spaces:
Sleeping
Sleeping
Yingxu He
commited on
Commit
·
51194b7
1
Parent(s):
76de8e8
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import time
|
4 |
|
5 |
-
from langchain.document_loaders import OnlinePDFLoader
|
6 |
|
7 |
from langchain.text_splitter import CharacterTextSplitter
|
8 |
|
@@ -19,10 +19,10 @@ from langchain.chains import ConversationalRetrievalChain
|
|
19 |
def loading_pdf():
|
20 |
return "Loading..."
|
21 |
|
22 |
-
def pdf_changes(
|
23 |
-
if
|
24 |
os.environ['OPENAI_API_KEY'] = open_ai_key
|
25 |
-
loader =
|
26 |
documents = loader.load()
|
27 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
28 |
texts = text_splitter.split_documents(documents)
|
@@ -86,7 +86,7 @@ with gr.Blocks(css=css) as demo:
|
|
86 |
|
87 |
with gr.Column():
|
88 |
openai_key = gr.Textbox(label="You OpenAI API key", type="password")
|
89 |
-
pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
|
90 |
with gr.Row():
|
91 |
langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
|
92 |
load_pdf = gr.Button("Load pdf to langchain")
|
@@ -95,7 +95,7 @@ with gr.Blocks(css=css) as demo:
|
|
95 |
question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
|
96 |
submit_btn = gr.Button("Send Message")
|
97 |
load_pdf.click(loading_pdf, None, langchain_status, queue=False)
|
98 |
-
load_pdf.click(pdf_changes, inputs=[
|
99 |
question.submit(add_text, [chatbot, question], [chatbot, question]).then(
|
100 |
bot, chatbot, chatbot
|
101 |
)
|
|
|
2 |
import os
|
3 |
import time
|
4 |
|
5 |
+
from langchain.document_loaders import OnlinePDFLoader, PyPDFLoader
|
6 |
|
7 |
from langchain.text_splitter import CharacterTextSplitter
|
8 |
|
|
|
19 |
def loading_pdf():
|
20 |
return "Loading..."
|
21 |
|
22 |
+
def pdf_changes(open_ai_key):
|
23 |
+
if open_ai_key is not None:
|
24 |
os.environ['OPENAI_API_KEY'] = open_ai_key
|
25 |
+
loader = PyPDFLoader("He Yingxu_2806.pdf")
|
26 |
documents = loader.load()
|
27 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
28 |
texts = text_splitter.split_documents(documents)
|
|
|
86 |
|
87 |
with gr.Column():
|
88 |
openai_key = gr.Textbox(label="You OpenAI API key", type="password")
|
89 |
+
# pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
|
90 |
with gr.Row():
|
91 |
langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
|
92 |
load_pdf = gr.Button("Load pdf to langchain")
|
|
|
95 |
question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
|
96 |
submit_btn = gr.Button("Send Message")
|
97 |
load_pdf.click(loading_pdf, None, langchain_status, queue=False)
|
98 |
+
load_pdf.click(pdf_changes, inputs=[openai_key], outputs=[langchain_status], queue=False)
|
99 |
question.submit(add_text, [chatbot, question], [chatbot, question]).then(
|
100 |
bot, chatbot, chatbot
|
101 |
)
|