tigerstride commited on
Commit
d8ef173
·
verified ·
1 Parent(s): b80a29a

Switch philly dataset URL

Browse files
Files changed (1) hide show
  1. retriever.py +10 -10
retriever.py CHANGED
@@ -52,24 +52,24 @@ def load_guest_dataset():
52
  return GuestInfoRetrieverTool(docs)
53
 
54
  def load_crash_data():
55
- # Public Philly crash data CSV (small demo file)
56
- url = "https://phl.carto.com/api/v2/sql?q=SELECT+*+FROM+vision_zero_crash+LIMIT+5000&format=csv"
57
  response = requests.get(url)
58
- with open("philly_crashes.csv", "wb") as f:
59
  f.write(response.content)
60
 
61
- df = pd.read_csv("philly_crashes.csv")
62
 
63
  # Convert to LangChain documents
64
  docs = []
65
  for _, row in df.iterrows():
66
  content = "\n".join([
67
- f"Date: {row.get('crash_date', 'N/A')}",
68
- f"Location: {row.get('location', 'N/A')}",
69
- f"Injury Count: {row.get('injury_count', 'N/A')}",
70
- f"Fatalities: {row.get('fatal_count', 'N/A')}",
71
- f"Crash Type: {row.get('crash_type', 'N/A')}",
72
- f"Weather: {row.get('weather', 'N/A')}"
73
  ])
74
  docs.append(Document(page_content=content, metadata={"id": row.get("id", "unknown")}))
75
 
 
52
  return GuestInfoRetrieverTool(docs)
53
 
54
  def load_crash_data():
55
+ # Public Philly crash fatality (csv)
56
+ url = "https://phl.carto.com/api/v2/sql?filename=fatal_crashes&format=csv&skipfields=cartodb_id,the_geom,the_geom_webmercator&q=SELECT%20*,%20ST_Y(the_geom)%20AS%20lat,%20ST_X(the_geom)%20AS%20lng%20FROM%20fatal_crashes"
57
  response = requests.get(url)
58
+ with open("fatal_crashes.csv", "wb") as f:
59
  f.write(response.content)
60
 
61
+ df = pd.read_csv("fatal_crashes.csv")
62
 
63
  # Convert to LangChain documents
64
  docs = []
65
  for _, row in df.iterrows():
66
  content = "\n".join([
67
+ f"Year: {row.get('year', 'N/A')}",
68
+ f"Street: {row.get('primary_st', 'N/A')}",
69
+ f"Age: {row.get('age', 'N/A')}",
70
+ f"Arrest: {row.get('arrest_yes', 'N/A')}",
71
+ f"Crash Type: {row.get('veh2', 'N/A')}",
72
+ f"Outcome: {row.get('investigat', 'N/A')}"
73
  ])
74
  docs.append(Document(page_content=content, metadata={"id": row.get("id", "unknown")}))
75