Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -73,14 +73,11 @@ if submit_button and query:
|
|
73 |
if uploaded_files:
|
74 |
pdf_text = extract_text_from_pdfs(uploaded_files)
|
75 |
|
76 |
-
# Prepare the input prompt
|
77 |
prompt = f"""
|
78 |
-
### Instruction and Input:
|
79 |
Based on the following context/document:
|
80 |
{pdf_text}
|
81 |
Please answer the question: {query}
|
82 |
-
|
83 |
-
### Response:
|
84 |
"""
|
85 |
|
86 |
# Encode the input text
|
@@ -97,15 +94,16 @@ if submit_button and query:
|
|
97 |
no_repeat_ngram_size=5,
|
98 |
)
|
99 |
|
100 |
-
# Decode the response
|
101 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
102 |
|
103 |
# Update chat history
|
104 |
-
st.session_state.chat_history.append((query,
|
105 |
|
106 |
# Display chat history
|
107 |
if st.session_state.chat_history:
|
108 |
-
for
|
109 |
-
st.markdown(f"**Question
|
110 |
st.markdown(f"**Answer:** {a}")
|
111 |
st.write("---")
|
|
|
73 |
if uploaded_files:
|
74 |
pdf_text = extract_text_from_pdfs(uploaded_files)
|
75 |
|
76 |
+
# Prepare the input prompt without unnecessary headers
|
77 |
prompt = f"""
|
|
|
78 |
Based on the following context/document:
|
79 |
{pdf_text}
|
80 |
Please answer the question: {query}
|
|
|
|
|
81 |
"""
|
82 |
|
83 |
# Encode the input text
|
|
|
94 |
no_repeat_ngram_size=5,
|
95 |
)
|
96 |
|
97 |
+
# Decode and clean the response
|
98 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
99 |
+
response_clean = response.replace("### Instruction and Input:", "").replace("### Response:", "").strip()
|
100 |
|
101 |
# Update chat history
|
102 |
+
st.session_state.chat_history.append((query, response_clean))
|
103 |
|
104 |
# Display chat history
|
105 |
if st.session_state.chat_history:
|
106 |
+
for q, a in st.session_state.chat_history:
|
107 |
+
st.markdown(f"**Question:** {q}")
|
108 |
st.markdown(f"**Answer:** {a}")
|
109 |
st.write("---")
|