captain-awesome commited on
Commit
b64d852
·
1 Parent(s): 3d9bf2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -35
app.py CHANGED
@@ -390,40 +390,39 @@ def retrieve_bot_answer(query):
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:
413
- llm = load_model()
414
- prompt = set_custom_prompt()
415
- CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
416
- loaded_documents = load_document(uploaded_files)
417
- db = create_vector_database(loaded_documents)
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()
 
390
 
391
 
392
 
393
+
394
+ app = GradiOApp(title="Docuverse")
395
+
396
+ # Upload files
397
+ uploaded_files = app.file_uploader("Upload your documents", types=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"], multiple=True)
398
+
399
+ if uploaded_files:
400
+ # Process uploaded files
401
+ for uploaded_file in uploaded_files:
402
+ print(f"Uploaded: {uploaded_file.name}")
403
+ print(f"Uploaded: {type(uploaded_file)}")
404
+
405
+ print("Chat with the Document:")
406
+ query = app.text_input("Ask a question:")
407
+
408
+ if app.button("Get Answer"):
409
+ if query:
410
+ # Load model, set prompts, create vector database, and retrieve answer
411
+ try:
412
+ llm = load_model()
413
+ prompt = set_custom_prompt()
414
+ CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
415
+ loaded_documents = load_document(uploaded_files)
416
+ db = create_vector_database(loaded_documents)
417
+ response = retrieve_bot_answer(query)
418
+
419
+ # Display bot response
420
+ print("Bot Response:")
421
+ print(response)
422
+ except Exception as e:
423
+ print(f"An error occurred: {str(e)}")
424
+ else:
425
+ print("Please enter a question.")
 
426
 
427
  if __name__ == "__main__":
428
+ app.run()