Update app.py
Browse files
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 |
-
|
23 |
-
|
24 |
-
|
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 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
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()
|
|