Switch philly dataset URL
Browse files- 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
|
| 56 |
-
url = "https://phl.carto.com/api/v2/sql?
|
| 57 |
response = requests.get(url)
|
| 58 |
-
with open("
|
| 59 |
f.write(response.content)
|
| 60 |
|
| 61 |
-
df = pd.read_csv("
|
| 62 |
|
| 63 |
# Convert to LangChain documents
|
| 64 |
docs = []
|
| 65 |
for _, row in df.iterrows():
|
| 66 |
content = "\n".join([
|
| 67 |
-
f"
|
| 68 |
-
f"
|
| 69 |
-
f"
|
| 70 |
-
f"
|
| 71 |
-
f"Crash Type: {row.get('
|
| 72 |
-
f"
|
| 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 |
|