Files changed (1) hide show
  1. app.py +29 -33
app.py CHANGED
@@ -11,7 +11,7 @@ from pathlib import Path
11
  from time import sleep
12
  import random
13
  import string
14
-
15
  import os
16
  from dotenv import load_dotenv
17
  load_dotenv()
@@ -19,9 +19,9 @@ load_dotenv()
19
  st.set_page_config(page_title="Open AI Doc-Chat Assistant", layout="wide")
20
  st.subheader("Open AI Doc-Chat Assistant: Life Enhancing with AI!")
21
 
22
- #css_file = "main.css"
23
- #with open(css_file) as f:
24
- # st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
25
 
26
  HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
27
 
@@ -45,36 +45,32 @@ new_index = VectorStoreIndex.from_documents(
45
  )
46
 
47
  new_index.storage_context.persist("random_string")
48
-
49
  storage_context = StorageContext.from_defaults(persist_dir="random_string")
50
-
51
  loadedindex = load_index_from_storage(storage_context=storage_context, service_context=service_context)
52
-
53
  query_engine = loadedindex.as_query_engine()
54
 
55
- while True:
56
- try:
57
- question = st.text_input("Enter your query here:")
58
- print("Your query:\n"+question)
59
- if question.strip().isspace():
60
- st.write("Query Empty. Please enter valid query first.")
61
- break
62
- elif question == "":
63
- # st.write("Query Empty. Please enter valid query first.")
64
- break
65
- elif question.strip() == "":
66
- st.write("Query Empty. Please enter valid query first.")
67
- break
68
- elif question.isspace():
69
- st.write("Query Empty. Please enter valid query first.")
70
- break
71
- elif question=="exit":
72
- break
73
- elif question!="":
74
- initial_response = query_engine.query(question)
75
- temp_ai_response=str(initial_response)
76
- final_ai_response=temp_ai_response.partition('<|end|>')[0]
77
- print("AI Response:\n"+final_ai_response)
78
- st.write("AI Response:\n\n"+final_ai_response)
79
- except Exception as e:
80
- st.stop()
 
11
  from time import sleep
12
  import random
13
  import string
14
+ import sys
15
  import os
16
  from dotenv import load_dotenv
17
  load_dotenv()
 
19
  st.set_page_config(page_title="Open AI Doc-Chat Assistant", layout="wide")
20
  st.subheader("Open AI Doc-Chat Assistant: Life Enhancing with AI!")
21
 
22
+ css_file = "main.css"
23
+ with open(css_file) as f:
24
+ st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
25
 
26
  HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
27
 
 
45
  )
46
 
47
  new_index.storage_context.persist("random_string")
 
48
  storage_context = StorageContext.from_defaults(persist_dir="random_string")
 
49
  loadedindex = load_index_from_storage(storage_context=storage_context, service_context=service_context)
 
50
  query_engine = loadedindex.as_query_engine()
51
 
52
+ question = st.text_input("Enter your query here:")
53
+ display_output_text = st.checkbox("Check AI Repsonse", key="key_checkbox", help="Check me to get AI Response.")
54
+
55
+ with st.sidebar:
56
+ st.subheader("Valuation.pdf furnished background!")
57
+ st.write("Disclaimer: This app is for information purpose only. NO liability could be claimed against whoever associated with this app in any manner. User should consult a qualified legal professional for legal advice.")
58
+ st.sidebar.markdown("Contact: [[email protected]](mailto:[email protected])")
59
+ st.sidebar.markdown('WeChat: <span class="blue-underline">pat2win</span>, or scan the code below.', unsafe_allow_html=True)
60
+ st.image(wechat_image)
61
+ st.sidebar.markdown('<span class="blue-underline">Life Enhancing with AI.</span>', unsafe_allow_html=True)
62
+ st.subheader("Enjoy chatting!")
63
+
64
+ if question !="" and not question.strip().isspace() and not question == "" and not question.strip() == "" and not question.isspace():
65
+ if display_output_text==True:
66
+ with st.spinner("AI Thinking...Please wait a while to Cheers!"):
67
+ initial_response = query_engine.query(question)
68
+ temp_ai_response=str(initial_response)
69
+ final_ai_response=temp_ai_response.partition('<|end|>')[0]
70
+ st.write("AI Response:\n\n"+final_ai_response)
71
+ else:
72
+ print("Check the Checkbox to get AI Response.")
73
+ sys.exit()
74
+ else:
75
+ print("Please enter your question first.")
76
+ st.stop()