Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,13 +36,18 @@ if not GOOGLE_API_KEY:
|
|
36 |
# Configure the API key
|
37 |
genai.configure(api_key=GOOGLE_API_KEY)
|
38 |
|
39 |
-
def get_pdf_text(
|
40 |
-
"""Extract text from
|
41 |
text = ""
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
return text
|
47 |
|
48 |
def get_text_chunks(text):
|
@@ -119,7 +124,10 @@ def main():
|
|
119 |
st.set_page_config(page_title="Robi AI Customer Service", page_icon="π±")
|
120 |
|
121 |
# Display Logo
|
122 |
-
|
|
|
|
|
|
|
123 |
|
124 |
# Title and Description
|
125 |
st.title("πΆ Robi AI Customer Service & Recommendation System")
|
@@ -197,16 +205,20 @@ def main():
|
|
197 |
st.header("π Documents:")
|
198 |
# Check if the FAISS index exists
|
199 |
if not os.path.exists("faiss_index/index.faiss"):
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
raw_text
|
205 |
-
|
206 |
-
|
207 |
-
|
|
|
|
|
|
|
|
|
208 |
else:
|
209 |
st.info("FAISS index loaded from 'faiss_index'.")
|
210 |
|
211 |
if __name__ == "__main__":
|
212 |
-
main()
|
|
|
36 |
# Configure the API key
|
37 |
genai.configure(api_key=GOOGLE_API_KEY)
|
38 |
|
39 |
+
def get_pdf_text(pdf_path):
|
40 |
+
"""Extract text from a PDF document."""
|
41 |
text = ""
|
42 |
+
try:
|
43 |
+
with open(pdf_path, "rb") as pdf_file:
|
44 |
+
pdf_reader = PdfReader(pdf_file)
|
45 |
+
for page in pdf_reader.pages:
|
46 |
+
extracted_text = page.extract_text()
|
47 |
+
if extracted_text:
|
48 |
+
text += extracted_text
|
49 |
+
except Exception as e:
|
50 |
+
st.error(f"Error reading PDF file: {e}")
|
51 |
return text
|
52 |
|
53 |
def get_text_chunks(text):
|
|
|
124 |
st.set_page_config(page_title="Robi AI Customer Service", page_icon="π±")
|
125 |
|
126 |
# Display Logo
|
127 |
+
if os.path.exists("robi_logo.png"):
|
128 |
+
st.image("robi_logo.png", width=200) # Ensure you have a 'robi_logo.png' in your project directory
|
129 |
+
else:
|
130 |
+
st.warning("Logo image 'robi_logo.png' not found. Please add it to the project directory.")
|
131 |
|
132 |
# Title and Description
|
133 |
st.title("πΆ Robi AI Customer Service & Recommendation System")
|
|
|
205 |
st.header("π Documents:")
|
206 |
# Check if the FAISS index exists
|
207 |
if not os.path.exists("faiss_index/index.faiss"):
|
208 |
+
pdf_path = "customerservicebot.pdf" # Default PDF file
|
209 |
+
if os.path.exists(pdf_path):
|
210 |
+
with st.spinner(f"Processing '{pdf_path}'..."):
|
211 |
+
raw_text = get_pdf_text(pdf_path)
|
212 |
+
if raw_text:
|
213 |
+
text_chunks = get_text_chunks(raw_text)
|
214 |
+
get_vector_store(text_chunks)
|
215 |
+
st.success(f"'{pdf_path}' processed and FAISS index created.")
|
216 |
+
else:
|
217 |
+
st.error(f"No text extracted from '{pdf_path}'. Please check the PDF content.")
|
218 |
+
else:
|
219 |
+
st.error(f"Default PDF '{pdf_path}' not found. Please add it to the project directory.")
|
220 |
else:
|
221 |
st.info("FAISS index loaded from 'faiss_index'.")
|
222 |
|
223 |
if __name__ == "__main__":
|
224 |
+
main()
|