Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -50,22 +50,20 @@ def get_conversational_chain():
|
|
50 |
return chain
|
51 |
|
52 |
def user_input(user_question, api_key):
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
# Convert text to speech for each response
|
68 |
-
text_to_speech(text)
|
69 |
|
70 |
def main():
|
71 |
st.set_page_config(layout="wide")
|
@@ -81,10 +79,6 @@ def main():
|
|
81 |
# Main column for displaying extracted text and user interaction
|
82 |
col1, col2 = st.columns([1, 2])
|
83 |
|
84 |
-
# Initialize raw_text as None initially
|
85 |
-
raw_text = None
|
86 |
-
submitted = False
|
87 |
-
|
88 |
if pdf_docs:
|
89 |
with col1:
|
90 |
if st.button("Submit"):
|
@@ -93,25 +87,24 @@ def main():
|
|
93 |
text_chunks = get_text_chunks(raw_text)
|
94 |
get_vector_store(text_chunks, api_key)
|
95 |
st.success("Processing Complete")
|
96 |
-
|
97 |
-
|
98 |
-
if pdf_docs:
|
99 |
with col1:
|
100 |
user_question = st.text_input("Ask a question from the Docs")
|
101 |
if user_question:
|
102 |
user_input(user_question, api_key)
|
103 |
-
raw_text = get_pdf_text(pdf_docs)
|
104 |
-
submitted = True
|
105 |
-
else:
|
106 |
-
with col1:
|
107 |
-
st.write("Please upload a document first to ask questions.")
|
108 |
|
109 |
-
# Display extracted text
|
110 |
-
if raw_text
|
111 |
with col2:
|
112 |
st.subheader("Extracted Text from PDF:")
|
113 |
st.text(raw_text)
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
|
116 |
if __name__ == "__main__":
|
117 |
main()
|
|
|
50 |
return chain
|
51 |
|
52 |
def user_input(user_question, api_key):
|
53 |
+
embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=api_key, model_name="sentence-transformers/all-MiniLM-l6-v2")
|
54 |
+
new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
55 |
+
docs = new_db.similarity_search(user_question)
|
56 |
+
chain = get_conversational_chain()
|
57 |
+
response = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
|
58 |
+
st.write("Replies:")
|
59 |
+
if isinstance(response["output_text"], str):
|
60 |
+
response_list = [response["output_text"]]
|
61 |
+
else:
|
62 |
+
response_list = response["output_text"]
|
63 |
+
for text in response_list:
|
64 |
+
st.write(text)
|
65 |
+
# Convert text to speech for each response
|
66 |
+
text_to_speech(text)
|
|
|
|
|
67 |
|
68 |
def main():
|
69 |
st.set_page_config(layout="wide")
|
|
|
79 |
# Main column for displaying extracted text and user interaction
|
80 |
col1, col2 = st.columns([1, 2])
|
81 |
|
|
|
|
|
|
|
|
|
82 |
if pdf_docs:
|
83 |
with col1:
|
84 |
if st.button("Submit"):
|
|
|
87 |
text_chunks = get_text_chunks(raw_text)
|
88 |
get_vector_store(text_chunks, api_key)
|
89 |
st.success("Processing Complete")
|
90 |
+
|
91 |
+
# Check if PDF documents are uploaded and processing is complete
|
92 |
+
if pdf_docs and raw_text:
|
93 |
with col1:
|
94 |
user_question = st.text_input("Ask a question from the Docs")
|
95 |
if user_question:
|
96 |
user_input(user_question, api_key)
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
# Display extracted text if available
|
99 |
+
if raw_text:
|
100 |
with col2:
|
101 |
st.subheader("Extracted Text from PDF:")
|
102 |
st.text(raw_text)
|
103 |
+
|
104 |
+
# Show message if no PDF documents are uploaded
|
105 |
+
if not pdf_docs:
|
106 |
+
with col1:
|
107 |
+
st.write("Please upload a document first to proceed.")
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
main()
|