Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,9 @@ from langchain.chains import RetrievalQA # for conversing with chatGPT
|
|
10 |
from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
|
11 |
|
12 |
|
|
|
|
|
|
|
13 |
def load_pdf(pdf_doc, open_ai_key):
|
14 |
if openai_key is not None:
|
15 |
os.environ['OPENAI_API_KEY'] = open_ai_key
|
@@ -46,21 +49,26 @@ css = """container{max-width:700px; margin-left:auto; margin-right:auto,padding:
|
|
46 |
with gr.Blocks(css=css,theme=gr.themes.Monochrome()) as demo:
|
47 |
gr.HTML(html)
|
48 |
with gr.Column():
|
49 |
-
gr.
|
50 |
-
openai_key = gr.Textbox(label="Your OpenAI API key", type="password")
|
51 |
pdf_doc = gr.File(label="Load a pdf",file_types=['.pdf'],type='file')
|
52 |
with gr.Row():
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
-
|
58 |
-
input = gr.Textbox(label="Type in your question")
|
59 |
-
output = gr.Textbox(label="output")
|
60 |
-
submit_query = gr.Button("submit")
|
61 |
|
62 |
-
load_pdf.click(load_pdf,inputs=[pdf_doc, openai_key],outputs=status)
|
63 |
|
64 |
-
submit_query.click(answer_query,input,output)
|
65 |
|
66 |
-
demo.launch()
|
|
|
10 |
from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
|
11 |
|
12 |
|
13 |
+
def loading_pdf():
|
14 |
+
return "Loading..."
|
15 |
+
|
16 |
def load_pdf(pdf_doc, open_ai_key):
|
17 |
if openai_key is not None:
|
18 |
os.environ['OPENAI_API_KEY'] = open_ai_key
|
|
|
49 |
with gr.Blocks(css=css,theme=gr.themes.Monochrome()) as demo:
|
50 |
gr.HTML(html)
|
51 |
with gr.Column():
|
52 |
+
openai_key = gr.Textbox(label="Your GPT-4 OpenAI API key", type="password")
|
|
|
53 |
pdf_doc = gr.File(label="Load a pdf",file_types=['.pdf'],type='file')
|
54 |
with gr.Row():
|
55 |
+
langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
|
56 |
+
load_pdf = gr.Button("Load PDF to LangChain")
|
57 |
+
|
58 |
+
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
|
59 |
+
question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
|
60 |
+
submit_btn = gr.Button("Send Message")
|
61 |
+
load_pdf.click(loading_pdf, None, langchain_status, queue=False)
|
62 |
+
load_pdf.click(load_pdf, inputs=[pdf_doc, openai_key], outputs=[langchain_status], queue=False)
|
63 |
+
|
64 |
+
question.submit(answer_query, [question], [question]).then(
|
65 |
+
bot, chatbot, chatbot
|
66 |
+
)
|
67 |
+
submit_btn.click(answer_query, [chatbot,question], [chatbot, question]).then(
|
68 |
+
bot, chatbot, chatbot)
|
69 |
|
70 |
|
71 |
+
demo.launch()
|
|
|
|
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|