captain-awesome commited on
Commit
bafdce5
1 Parent(s): d53f040

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -32
app.py CHANGED
@@ -350,39 +350,73 @@ def retrieve_bot_answer(query):
350
 
351
  # from your_module import load_model, set_custom_prompt, set_custom_prompt_condense, create_vector_database, retrieve_bot_answer
352
 
353
- def main():
354
- st.title("Docuverse")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
 
 
356
  # Upload files
357
- 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)
358
-
359
- if uploaded_files:
360
- # Process uploaded files
361
- for uploaded_file in uploaded_files:
362
- st.write(f"Uploaded: {uploaded_file.name}")
363
- st.write(f"Uploaded: {type(uploaded_file)}")
364
-
365
- st.write("Chat with the Document:")
366
- query = st.text_input("Ask a question:")
367
-
368
- if st.button("Get Answer"):
369
- if query:
370
- # Load model, set prompts, create vector database, and retrieve answer
371
- try:
372
- llm = load_model()
373
- prompt = set_custom_prompt()
374
- CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
375
- loaded_documents = load_document(uploaded_files)
376
- db = create_vector_database(loaded_documents)
377
- response = retrieve_bot_answer(query)
378
-
379
- # Display bot response
380
- st.write("Bot Response:")
381
- st.write(response)
382
- except Exception as e:
383
- st.error(f"An error occurred: {str(e)}")
384
- else:
385
- st.warning("Please enter a question.")
386
 
387
  if __name__ == "__main__":
388
- main()
 
350
 
351
  # from your_module import load_model, set_custom_prompt, set_custom_prompt_condense, create_vector_database, retrieve_bot_answer
352
 
353
+ # def main():
354
+ # st.title("Docuverse")
355
+
356
+ # # Upload files
357
+ # 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)
358
+
359
+ # if uploaded_files:
360
+ # # Process uploaded files
361
+ # for uploaded_file in uploaded_files:
362
+ # st.write(f"Uploaded: {uploaded_file.name}")
363
+ # st.write(f"Uploaded: {type(uploaded_file)}")
364
+
365
+ # st.write("Chat with the Document:")
366
+ # query = st.text_input("Ask a question:")
367
+
368
+ # if st.button("Get Answer"):
369
+ # if query:
370
+ # # Load model, set prompts, create vector database, and retrieve answer
371
+ # try:
372
+ # llm = load_model()
373
+ # prompt = set_custom_prompt()
374
+ # CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
375
+ # loaded_documents = load_document(uploaded_files)
376
+ # db = create_vector_database(loaded_documents)
377
+ # response = retrieve_bot_answer(query)
378
+
379
+ # # Display bot response
380
+ # st.write("Bot Response:")
381
+ # st.write(response)
382
+ # except Exception as e:
383
+ # st.error(f"An error occurred: {str(e)}")
384
+ # else:
385
+ # st.warning("Please enter a question.")
386
+
387
+ # if __name__ == "__main__":
388
+ # main()
389
+
390
+ import gradio as gr
391
 
392
+ def main():
393
  # Upload files
394
+ 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"])
395
+
396
+ # Process uploaded files
397
+ def process_files(files):
398
+ for file in files:
399
+ print(f"Uploaded: {file.name}")
400
+ print(f"Uploaded: {type(file)}")
401
+
402
+ query = gr.inputs.text(label="Ask a question:")
403
+
404
+ # Load model, set prompts, create vector database, and retrieve answer
405
+ def get_answer(query, files):
406
+ try:
407
+ llm = load_model()
408
+ prompt = set_custom_prompt()
409
+ CONDENSE_QUESTION_PROMPT = set_custom_prompt_condense()
410
+ loaded_documents = load_document(files)
411
+ db = create_vector_database(loaded_documents)
412
+ response = retrieve_bot_answer(query)
413
+
414
+ # Display bot response
415
+ return response
416
+ except Exception as e:
417
+ return f"An error occurred: {str(e)}"
418
+
419
+ gr.outputs.text(get_answer, query, file_uploader)
 
 
 
420
 
421
  if __name__ == "__main__":
422
+ gr.Interface(main).launch()