Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ def summarize_pdf(file, openai_api_key):
|
|
30 |
vector_store = FAISS.from_documents(documents, embeddings)
|
31 |
|
32 |
# Create a RetrievalQA chain for summarization
|
33 |
-
llm = ChatOpenAI(model="gpt-
|
34 |
qa_chain = RetrievalQA.from_chain_type(
|
35 |
llm=llm,
|
36 |
chain_type="stuff",
|
@@ -56,7 +56,7 @@ def query_pdf(file, user_query, openai_api_key):
|
|
56 |
vector_store = FAISS.from_documents(documents, embeddings)
|
57 |
|
58 |
# Create a RetrievalQA chain for querying the document
|
59 |
-
llm = ChatOpenAI(model="gpt-
|
60 |
qa_chain = RetrievalQA.from_chain_type(
|
61 |
llm=llm,
|
62 |
chain_type="stuff",
|
@@ -81,16 +81,27 @@ def create_gradio_interface():
|
|
81 |
pdf_file = gr.File(label="Upload PDF Document")
|
82 |
summarize_btn = gr.Button("Summarize")
|
83 |
summary_output = gr.Textbox(label="Summary", interactive=False)
|
84 |
-
|
|
|
|
|
85 |
summarize_btn.click(summarize_pdf, inputs=[pdf_file, openai_api_key_input], outputs=summary_output)
|
|
|
|
|
|
|
86 |
|
87 |
with gr.Tab("Ask Questions"):
|
88 |
with gr.Row():
|
89 |
pdf_file_q = gr.File(label="Upload PDF Document")
|
90 |
user_input = gr.Textbox(label="Enter your question")
|
91 |
answer_output = gr.Textbox(label="Answer", interactive=False)
|
92 |
-
|
|
|
|
|
93 |
user_input.submit(query_pdf, inputs=[pdf_file_q, user_input, openai_api_key_input], outputs=answer_output)
|
|
|
|
|
|
|
|
|
94 |
user_input.submit(None, None, answer_output) # Clear answer when typing new query
|
95 |
|
96 |
return demo
|
|
|
30 |
vector_store = FAISS.from_documents(documents, embeddings)
|
31 |
|
32 |
# Create a RetrievalQA chain for summarization
|
33 |
+
llm = ChatOpenAI(model="gpt-4", openai_api_key=openai_api_key) # Passing API key here
|
34 |
qa_chain = RetrievalQA.from_chain_type(
|
35 |
llm=llm,
|
36 |
chain_type="stuff",
|
|
|
56 |
vector_store = FAISS.from_documents(documents, embeddings)
|
57 |
|
58 |
# Create a RetrievalQA chain for querying the document
|
59 |
+
llm = ChatOpenAI(model="gpt-4", openai_api_key=openai_api_key) # Passing API key here
|
60 |
qa_chain = RetrievalQA.from_chain_type(
|
61 |
llm=llm,
|
62 |
chain_type="stuff",
|
|
|
81 |
pdf_file = gr.File(label="Upload PDF Document")
|
82 |
summarize_btn = gr.Button("Summarize")
|
83 |
summary_output = gr.Textbox(label="Summary", interactive=False)
|
84 |
+
clear_btn_summary = gr.Button("Clear Response")
|
85 |
+
|
86 |
+
# Summarize Button Logic
|
87 |
summarize_btn.click(summarize_pdf, inputs=[pdf_file, openai_api_key_input], outputs=summary_output)
|
88 |
+
|
89 |
+
# Clear Response Button Logic for Summary Tab
|
90 |
+
clear_btn_summary.click(lambda: "", inputs=[], outputs=summary_output)
|
91 |
|
92 |
with gr.Tab("Ask Questions"):
|
93 |
with gr.Row():
|
94 |
pdf_file_q = gr.File(label="Upload PDF Document")
|
95 |
user_input = gr.Textbox(label="Enter your question")
|
96 |
answer_output = gr.Textbox(label="Answer", interactive=False)
|
97 |
+
clear_btn_answer = gr.Button("Clear Response")
|
98 |
+
|
99 |
+
# Submit Question Logic
|
100 |
user_input.submit(query_pdf, inputs=[pdf_file_q, user_input, openai_api_key_input], outputs=answer_output)
|
101 |
+
|
102 |
+
# Clear Response Button Logic for Answer Tab
|
103 |
+
clear_btn_answer.click(lambda: "", inputs=[], outputs=answer_output)
|
104 |
+
|
105 |
user_input.submit(None, None, answer_output) # Clear answer when typing new query
|
106 |
|
107 |
return demo
|