Spaces:
Running
Running
File size: 899 Bytes
4363820 |
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 |
# src/utils/data_loader.py
import pandas as pd
import json
def load_restaurant_data(file_path: str) -> pd.DataFrame:
"""
Load restaurant data from JSON file into a DataFrame.
Args:
file_path (str): Path to the JSON file.
Returns:
pd.DataFrame: DataFrame containing restaurant data.
"""
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
df = pd.DataFrame(data)
# Create a text field for embedding and BM25
df['text'] = df.apply(
lambda row: f"{row['name']} ({row['cuisine']}): {', '.join(row['dishes'])}. "
f"Price: {row['price_range']}, Distance: {row['distance']} km, "
f"Rating: {row['rating']}. Description: {row['description']}",
axis=1
)
return df
if __name__ == "__main__":
print(load_restaurant_data("./data/restaurants.json")) |