Spaces:
Running
Running
File size: 969 Bytes
dc4b86a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import pandas as pd
import numpy as np
def get_dataframe(file_path: str) -> pd.DataFrame:
'''Reads a CSV file and returns a Pandas DataFrame.
Args:
file_path: The path to the CSV file.
Returns:
pd.DataFrame: The loaded DataFrame.
'''
try:
df = pd.read_csv(file_path)
## Minor tweak to fix the escape sequence character
df['summaries'] = df['summaries'].str.replace('\xa0', '', regex=False)
return df
except FileNotFoundError:
print(f"Error: The file at {file_path} was not found.")
except pd.errors.EmptyDataError:
print(f"Error: The file at {file_path} is empty.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
def load_cache_embeddings(embedding_path: str="app_cache/summary_vectors.npy") -> np.ndarray:
'''Returns embeddings of the book summaries'''
emb = np.load(embedding_path)
emb = emb.astype(np.float32)
return emb |