captain-awesome commited on
Commit
c296508
1 Parent(s): d5d564a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -59
app.py CHANGED
@@ -351,73 +351,73 @@ 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
- # 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
- 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
+ # 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()