Spaces:
Runtime error
Runtime error
Commit
·
23ae001
1
Parent(s):
c296508
Update app.py
Browse files
app.py
CHANGED
@@ -351,22 +351,62 @@ def retrieve_bot_answer(query):
|
|
351 |
|
352 |
# from your_module import load_model, set_custom_prompt, set_custom_prompt_condense, create_vector_database, retrieve_bot_answer
|
353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
def main():
|
355 |
-
|
356 |
|
357 |
# Upload files
|
358 |
-
uploaded_files =
|
359 |
|
360 |
if uploaded_files:
|
361 |
# Process uploaded files
|
362 |
for uploaded_file in uploaded_files:
|
363 |
-
|
364 |
-
|
365 |
|
366 |
-
|
367 |
-
query =
|
368 |
|
369 |
-
if
|
370 |
if query:
|
371 |
# Load model, set prompts, create vector database, and retrieve answer
|
372 |
try:
|
@@ -378,46 +418,12 @@ def main():
|
|
378 |
response = retrieve_bot_answer(query)
|
379 |
|
380 |
# Display bot response
|
381 |
-
|
382 |
-
|
383 |
except Exception as e:
|
384 |
-
|
385 |
else:
|
386 |
-
|
387 |
|
388 |
if __name__ == "__main__":
|
389 |
-
main(
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
# def main():
|
394 |
-
# # Upload files
|
395 |
-
# file_uploader = gr.inputs.file_uploader(multiple=True, accept_multiple_files=True, types=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"])
|
396 |
-
|
397 |
-
# # Process uploaded files
|
398 |
-
# def process_files(files):
|
399 |
-
# for file in files:
|
400 |
-
# print(f"Uploaded: {file.name}")
|
401 |
-
# print(f"Uploaded: {type(file)}")
|
402 |
-
|
403 |
-
# query = gr.inputs.text(label="Ask a question:")
|
404 |
-
|
405 |
-
# # Load model, set prompts, create vector database, and retrieve answer
|
406 |
-
# def get_answer(query, files):
|
407 |
-
# try:
|
408 |
-
# llm = load_model()
|
409 |
-
# prompt = set_custom_prompt()
|
410 |
-
# CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
|
411 |
-
# loaded_documents = load_document(files)
|
412 |
-
# db = create_vector_database(loaded_documents)
|
413 |
-
# response = retrieve_bot_answer(query)
|
414 |
-
|
415 |
-
# # Display bot response
|
416 |
-
# return response
|
417 |
-
# except Exception as e:
|
418 |
-
# return f"An error occurred: {str(e)}"
|
419 |
-
|
420 |
-
# gr.outputs.text(get_answer, query, file_uploader)
|
421 |
-
|
422 |
-
# if __name__ == "__main__":
|
423 |
-
# gr.Interface(main).launch()
|
|
|
351 |
|
352 |
# from your_module import load_model, set_custom_prompt, set_custom_prompt_condense, create_vector_database, retrieve_bot_answer
|
353 |
|
354 |
+
# def main():
|
355 |
+
# st.title("Docuverse")
|
356 |
+
|
357 |
+
# # Upload files
|
358 |
+
# uploaded_files = st.file_uploader("Upload your documents", type=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"], accept_multiple_files=True)
|
359 |
+
|
360 |
+
# if uploaded_files:
|
361 |
+
# # Process uploaded files
|
362 |
+
# for uploaded_file in uploaded_files:
|
363 |
+
# st.write(f"Uploaded: {uploaded_file.name}")
|
364 |
+
# st.write(f"Uploaded: {type(uploaded_file)}")
|
365 |
+
|
366 |
+
# st.write("Chat with the Document:")
|
367 |
+
# query = st.text_input("Ask a question:")
|
368 |
+
|
369 |
+
# if st.button("Get Answer"):
|
370 |
+
# if query:
|
371 |
+
# # Load model, set prompts, create vector database, and retrieve answer
|
372 |
+
# try:
|
373 |
+
# llm = load_model()
|
374 |
+
# prompt = set_custom_prompt()
|
375 |
+
# CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
|
376 |
+
# loaded_documents = load_document(uploaded_files)
|
377 |
+
# db = create_vector_database(loaded_documents)
|
378 |
+
# response = retrieve_bot_answer(query)
|
379 |
+
|
380 |
+
# # Display bot response
|
381 |
+
# st.write("Bot Response:")
|
382 |
+
# st.write(response)
|
383 |
+
# except Exception as e:
|
384 |
+
# st.error(f"An error occurred: {str(e)}")
|
385 |
+
# else:
|
386 |
+
# st.warning("Please enter a question.")
|
387 |
+
|
388 |
+
# if __name__ == "__main__":
|
389 |
+
# main()
|
390 |
+
|
391 |
+
|
392 |
+
|
393 |
+
@gr.app
|
394 |
def main():
|
395 |
+
title("Docuverse")
|
396 |
|
397 |
# Upload files
|
398 |
+
uploaded_files = gr.file_uploader("Upload your documents", types=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"], multiple=True)
|
399 |
|
400 |
if uploaded_files:
|
401 |
# Process uploaded files
|
402 |
for uploaded_file in uploaded_files:
|
403 |
+
print(f"Uploaded: {uploaded_file.name}")
|
404 |
+
print(f"Uploaded: {type(uploaded_file)}")
|
405 |
|
406 |
+
print("Chat with the Document:")
|
407 |
+
query = gr.text_input("Ask a question:")
|
408 |
|
409 |
+
if gr.button("Get Answer"):
|
410 |
if query:
|
411 |
# Load model, set prompts, create vector database, and retrieve answer
|
412 |
try:
|
|
|
418 |
response = retrieve_bot_answer(query)
|
419 |
|
420 |
# Display bot response
|
421 |
+
print("Bot Response:")
|
422 |
+
print(response)
|
423 |
except Exception as e:
|
424 |
+
print(f"An error occurred: {str(e)}")
|
425 |
else:
|
426 |
+
print("Please enter a question.")
|
427 |
|
428 |
if __name__ == "__main__":
|
429 |
+
main(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|