Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,7 @@ def load_any_file(file_path):
|
|
| 33 |
return loader.load()
|
| 34 |
|
| 35 |
|
|
|
|
| 36 |
def process_inputs(url, file):
|
| 37 |
data = []
|
| 38 |
if url:
|
|
@@ -44,7 +45,7 @@ def process_inputs(url, file):
|
|
| 44 |
data.extend(load_any_file(upload_file_path))
|
| 45 |
|
| 46 |
if not data:
|
| 47 |
-
return "Please provide a URL or a file to process.",
|
| 48 |
|
| 49 |
splitter = RecursiveCharacterTextSplitter(
|
| 50 |
separators=['\n\n', '\n', '.', ','],
|
|
@@ -55,7 +56,7 @@ def process_inputs(url, file):
|
|
| 55 |
vectorstore = FAISS.from_documents(docs, embeddings)
|
| 56 |
vectorstore.save_local(VECTOR_STORE_PATH)
|
| 57 |
|
| 58 |
-
return "β
Documents processed
|
| 59 |
|
| 60 |
|
| 61 |
def answer_question(query):
|
|
@@ -77,17 +78,22 @@ with gr.Blocks(title="InfoSEARCH") as demo:
|
|
| 77 |
|
| 78 |
with gr.Tab("π Upload or Link"):
|
| 79 |
with gr.Row():
|
| 80 |
-
url_input = gr.Textbox(label="
|
| 81 |
file_input = gr.File(label="Upload Document", file_types=[".pdf", ".txt", ".docx", ".html", ".htm"])
|
| 82 |
process_btn = gr.Button("π₯ Process Input")
|
| 83 |
process_status = gr.Textbox(label="Status", interactive=False)
|
|
|
|
| 84 |
|
| 85 |
with gr.Tab("β Ask a Question"):
|
| 86 |
query_input = gr.Textbox(label="Ask a question", placeholder="Type your question here and hit Enter")
|
| 87 |
answer_output = gr.Textbox(label="π§Ύ Answer", lines=4)
|
| 88 |
sources_output = gr.Textbox(label="π Sources", lines=3)
|
| 89 |
|
| 90 |
-
process_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
query_input.submit(fn=answer_question, inputs=query_input, outputs=[answer_output, sources_output])
|
| 92 |
|
| 93 |
|
|
|
|
| 33 |
return loader.load()
|
| 34 |
|
| 35 |
|
| 36 |
+
|
| 37 |
def process_inputs(url, file):
|
| 38 |
data = []
|
| 39 |
if url:
|
|
|
|
| 45 |
data.extend(load_any_file(upload_file_path))
|
| 46 |
|
| 47 |
if not data:
|
| 48 |
+
return "Please provide a URL or a file to process.", gr.update(visible=False), gr.update(visible=False)
|
| 49 |
|
| 50 |
splitter = RecursiveCharacterTextSplitter(
|
| 51 |
separators=['\n\n', '\n', '.', ','],
|
|
|
|
| 56 |
vectorstore = FAISS.from_documents(docs, embeddings)
|
| 57 |
vectorstore.save_local(VECTOR_STORE_PATH)
|
| 58 |
|
| 59 |
+
return "β
Documents processed successfully! Please switch to the 'Ask a Question' tab.", gr.update(visible=True), gr.update(visible=True)
|
| 60 |
|
| 61 |
|
| 62 |
def answer_question(query):
|
|
|
|
| 78 |
|
| 79 |
with gr.Tab("π Upload or Link"):
|
| 80 |
with gr.Row():
|
| 81 |
+
url_input = gr.Textbox(label="Upload URL", placeholder="Paste a news article URL")
|
| 82 |
file_input = gr.File(label="Upload Document", file_types=[".pdf", ".txt", ".docx", ".html", ".htm"])
|
| 83 |
process_btn = gr.Button("π₯ Process Input")
|
| 84 |
process_status = gr.Textbox(label="Status", interactive=False)
|
| 85 |
+
jump_notice = gr.Textbox(visible=False, interactive=False)
|
| 86 |
|
| 87 |
with gr.Tab("β Ask a Question"):
|
| 88 |
query_input = gr.Textbox(label="Ask a question", placeholder="Type your question here and hit Enter")
|
| 89 |
answer_output = gr.Textbox(label="π§Ύ Answer", lines=4)
|
| 90 |
sources_output = gr.Textbox(label="π Sources", lines=3)
|
| 91 |
|
| 92 |
+
process_btn.click(
|
| 93 |
+
fn=process_inputs,
|
| 94 |
+
inputs=[url_input, file_input],
|
| 95 |
+
outputs=[process_status, jump_notice, query_input]
|
| 96 |
+
)
|
| 97 |
query_input.submit(fn=answer_question, inputs=query_input, outputs=[answer_output, sources_output])
|
| 98 |
|
| 99 |
|