Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,8 +26,6 @@ def add_bg_from_local(image_file):
|
|
26 |
background-size: cover}}</style>""", unsafe_allow_html=True)
|
27 |
add_bg_from_local(image_bg)
|
28 |
|
29 |
-
#st.header("Welcome")
|
30 |
-
|
31 |
st.markdown("""
|
32 |
<svg width="600" height="100">
|
33 |
<text x="50%" y="50%" font-family="San serif" font-size="42px" fill="Black" text-anchor="middle" stroke="white"
|
@@ -36,7 +34,6 @@ st.markdown("""
|
|
36 |
</svg>
|
37 |
""", unsafe_allow_html=True)
|
38 |
|
39 |
-
|
40 |
def get_answer(query, chain):
|
41 |
try:
|
42 |
response = chain.invoke(query)
|
@@ -45,8 +42,6 @@ def get_answer(query, chain):
|
|
45 |
st.error(f"Error in get_answer: {e}")
|
46 |
return None
|
47 |
|
48 |
-
#st.title("MULTIMODAL DOC QA")
|
49 |
-
|
50 |
uploaded_file = st.file_uploader("File upload", type="pdf")
|
51 |
if uploaded_file is not None:
|
52 |
temp_file_path = os.path.join("temp", uploaded_file.name)
|
@@ -56,7 +51,6 @@ if uploaded_file is not None:
|
|
56 |
|
57 |
path = os.path.abspath(temp_file_path)
|
58 |
st.write(f"File saved to: {path}")
|
59 |
-
|
60 |
st.write("Document uploaded successfully!")
|
61 |
|
62 |
if st.button("Start Processing"):
|
@@ -82,7 +76,6 @@ st.markdown("""
|
|
82 |
</style>
|
83 |
""", unsafe_allow_html=True)
|
84 |
|
85 |
-
|
86 |
if user_input := st.chat_input("User Input"):
|
87 |
if 'chain' in st.session_state and 'image_vdb' in st.session_state:
|
88 |
chain = st.session_state['chain']
|
@@ -90,15 +83,24 @@ if user_input := st.chat_input("User Input"):
|
|
90 |
|
91 |
with st.chat_message("user"):
|
92 |
st.markdown(user_input)
|
93 |
-
|
94 |
-
|
95 |
with st.spinner("Generating Response..."):
|
96 |
response = get_answer(user_input, chain)
|
97 |
if response:
|
98 |
st.markdown(response)
|
99 |
with st.chat_message("assistant"):
|
100 |
st.markdown(response)
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
try:
|
103 |
query_and_print_results(image_vdb, user_input)
|
104 |
except Exception as e:
|
|
|
26 |
background-size: cover}}</style>""", unsafe_allow_html=True)
|
27 |
add_bg_from_local(image_bg)
|
28 |
|
|
|
|
|
29 |
st.markdown("""
|
30 |
<svg width="600" height="100">
|
31 |
<text x="50%" y="50%" font-family="San serif" font-size="42px" fill="Black" text-anchor="middle" stroke="white"
|
|
|
34 |
</svg>
|
35 |
""", unsafe_allow_html=True)
|
36 |
|
|
|
37 |
def get_answer(query, chain):
|
38 |
try:
|
39 |
response = chain.invoke(query)
|
|
|
42 |
st.error(f"Error in get_answer: {e}")
|
43 |
return None
|
44 |
|
|
|
|
|
45 |
uploaded_file = st.file_uploader("File upload", type="pdf")
|
46 |
if uploaded_file is not None:
|
47 |
temp_file_path = os.path.join("temp", uploaded_file.name)
|
|
|
51 |
|
52 |
path = os.path.abspath(temp_file_path)
|
53 |
st.write(f"File saved to: {path}")
|
|
|
54 |
st.write("Document uploaded successfully!")
|
55 |
|
56 |
if st.button("Start Processing"):
|
|
|
76 |
</style>
|
77 |
""", unsafe_allow_html=True)
|
78 |
|
|
|
79 |
if user_input := st.chat_input("User Input"):
|
80 |
if 'chain' in st.session_state and 'image_vdb' in st.session_state:
|
81 |
chain = st.session_state['chain']
|
|
|
83 |
|
84 |
with st.chat_message("user"):
|
85 |
st.markdown(user_input)
|
86 |
+
|
|
|
87 |
with st.spinner("Generating Response..."):
|
88 |
response = get_answer(user_input, chain)
|
89 |
if response:
|
90 |
st.markdown(response)
|
91 |
with st.chat_message("assistant"):
|
92 |
st.markdown(response)
|
93 |
+
|
94 |
+
# Save context in memory
|
95 |
+
memory.save_context(
|
96 |
+
{"role": "user", "content": user_input},
|
97 |
+
{"role": "assistant", "content": response}
|
98 |
+
)
|
99 |
+
|
100 |
+
# Append messages to session state for display
|
101 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
102 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
103 |
+
|
104 |
try:
|
105 |
query_and_print_results(image_vdb, user_input)
|
106 |
except Exception as e:
|