Spaces:
Running
Running
Sakshi
commited on
Commit
·
2856ddc
1
Parent(s):
d67de0b
fixed markdown_table_to_json in utils.py
Browse files- policy_analyser/utils.py +14 -0
policy_analyser/utils.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def markdown_table_to_json(markdown):
|
2 |
+
lines = markdown.strip().split("\n")
|
3 |
+
|
4 |
+
# Extract headers
|
5 |
+
headers = [h.strip() for h in lines[0].split("|") if h.strip()]
|
6 |
+
|
7 |
+
# Extract rows
|
8 |
+
rows = []
|
9 |
+
for line in lines[2:]: # Skip header and separator line
|
10 |
+
values = [v.strip() for v in line.split("|") if v.strip()]
|
11 |
+
row_dict = dict(zip(headers, values))
|
12 |
+
rows.append(row_dict)
|
13 |
+
|
14 |
+
return rows
|