Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,22 +50,22 @@ def get_conversational_chain():
|
|
| 50 |
return chain
|
| 51 |
|
| 52 |
def user_input(user_question, api_key):
|
| 53 |
-
st.spinner("Processing...")
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
def main():
|
| 71 |
st.set_page_config(layout="wide")
|
|
@@ -83,6 +83,7 @@ def main():
|
|
| 83 |
|
| 84 |
# Initialize raw_text as None initially
|
| 85 |
raw_text = None
|
|
|
|
| 86 |
|
| 87 |
if pdf_docs:
|
| 88 |
with col1:
|
|
@@ -92,8 +93,9 @@ def main():
|
|
| 92 |
text_chunks = get_text_chunks(raw_text)
|
| 93 |
get_vector_store(text_chunks, api_key)
|
| 94 |
st.success("Processing Complete")
|
|
|
|
| 95 |
|
| 96 |
-
if
|
| 97 |
with col1:
|
| 98 |
user_question = st.text_input("Ask a question from the Docs")
|
| 99 |
if user_question:
|
|
|
|
| 50 |
return chain
|
| 51 |
|
| 52 |
def user_input(user_question, api_key):
|
| 53 |
+
with st.spinner("Processing..."):
|
| 54 |
+
embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=api_key, model_name="sentence-transformers/all-MiniLM-l6-v2")
|
| 55 |
+
new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
| 56 |
+
docs = new_db.similarity_search(user_question)
|
| 57 |
+
chain = get_conversational_chain()
|
| 58 |
+
response = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
|
| 59 |
+
st.success("Processed")
|
| 60 |
+
st.write("Replies:")
|
| 61 |
+
if isinstance(response["output_text"], str):
|
| 62 |
+
response_list = [response["output_text"]]
|
| 63 |
+
else:
|
| 64 |
+
response_list = response["output_text"]
|
| 65 |
+
for text in response_list:
|
| 66 |
+
st.write(text)
|
| 67 |
+
# Convert text to speech for each response
|
| 68 |
+
text_to_speech(text)
|
| 69 |
|
| 70 |
def main():
|
| 71 |
st.set_page_config(layout="wide")
|
|
|
|
| 83 |
|
| 84 |
# Initialize raw_text as None initially
|
| 85 |
raw_text = None
|
| 86 |
+
submitted = False
|
| 87 |
|
| 88 |
if pdf_docs:
|
| 89 |
with col1:
|
|
|
|
| 93 |
text_chunks = get_text_chunks(raw_text)
|
| 94 |
get_vector_store(text_chunks, api_key)
|
| 95 |
st.success("Processing Complete")
|
| 96 |
+
submitted = True
|
| 97 |
|
| 98 |
+
if submitted:
|
| 99 |
with col1:
|
| 100 |
user_question = st.text_input("Ask a question from the Docs")
|
| 101 |
if user_question:
|