Spaces:
Runtime error
Runtime error
p23
#3
by
cholmes
- opened
- fiboa/app.py +7 -7
- fiboa/query.py +3 -4
- questions.md +3 -1
fiboa/app.py
CHANGED
@@ -42,7 +42,7 @@ and return the answer. Only limit for {top_k} when asked for "some" or "examples
|
|
42 |
This duckdb database includes full support for spatial queries, so it will understand most PostGIS-type
|
43 |
queries as well. Remember that you must cast blob column to a geom type using ST_GeomFromWKB(geometry) AS geometry
|
44 |
before any spatial operations. Do not use ST_GeomFromWKB for non-spatial queries.
|
45 |
-
If you are asked to "map" or "show on a map", then be
|
46 |
If asked to show a "table", you must not include the "geometry" column from the query results.
|
47 |
|
48 |
Use the following format: return only the SQLQuery to run. DO NOT use the prefix with "SQLQuery:".
|
@@ -59,7 +59,7 @@ There is no other column related to area information, especially not total_area
|
|
59 |
If you need to compute the total area, do it manually, with a SUM of the area column. You should always use the 'area' column - never use a 'total_area' column.
|
60 |
The column "perimeter" is in the unit meters, you may need to convert it to other units, e.g. kilometers.
|
61 |
The column "collection" contains the country codes for the Baltic states:
|
62 |
-
"
|
63 |
Be sure to always include the collection with the right country for any query about a specific country, including it in the WHERE clause.
|
64 |
|
65 |
If the user asks for 'percent' of crops or fields for one of the countries you must always calculate the percentage manually, by summing up the area manually. You total number of hectares to calculate the percentage from is 1583923 for Lithuania, 1788859 for latvia and 973945 for Estonia. If they don't specify a country use 4346727. If you use one of these be sure to always include the right collection in the where clause.
|
@@ -94,15 +94,15 @@ chain = create_sql_query_chain(llm, db, prompt=new_prompt, k=100)
|
|
94 |
Ask me about fiboa data (here: all baltic states)!
|
95 |
Request "a map" to get map output, or table for tabular output, e.g.
|
96 |
|
97 |
-
- Show a
|
98 |
-
- Show a map with the 10 largest sugar beet fields.
|
99 |
-
- What is the percent of oats in each country?
|
100 |
- Show a map with the largest field in Estonia
|
101 |
-
-
|
|
|
|
|
102 |
|
103 |
'''
|
104 |
|
105 |
-
example = "
|
106 |
with st.container():
|
107 |
if prompt := st.chat_input(example, key="chain"):
|
108 |
st.chat_message("user").write(prompt)
|
|
|
42 |
This duckdb database includes full support for spatial queries, so it will understand most PostGIS-type
|
43 |
queries as well. Remember that you must cast blob column to a geom type using ST_GeomFromWKB(geometry) AS geometry
|
44 |
before any spatial operations. Do not use ST_GeomFromWKB for non-spatial queries.
|
45 |
+
If you are asked to "map" or "show on a map", then be select the "geometry" column in your query.
|
46 |
If asked to show a "table", you must not include the "geometry" column from the query results.
|
47 |
|
48 |
Use the following format: return only the SQLQuery to run. DO NOT use the prefix with "SQLQuery:".
|
|
|
59 |
If you need to compute the total area, do it manually, with a SUM of the area column. You should always use the 'area' column - never use a 'total_area' column.
|
60 |
The column "perimeter" is in the unit meters, you may need to convert it to other units, e.g. kilometers.
|
61 |
The column "collection" contains the country codes for the Baltic states:
|
62 |
+
"ec_lt" for Latvia, "ec_lv" for Lithuania, "ec_es" for Estonia.
|
63 |
Be sure to always include the collection with the right country for any query about a specific country, including it in the WHERE clause.
|
64 |
|
65 |
If the user asks for 'percent' of crops or fields for one of the countries you must always calculate the percentage manually, by summing up the area manually. You total number of hectares to calculate the percentage from is 1583923 for Lithuania, 1788859 for latvia and 973945 for Estonia. If they don't specify a country use 4346727. If you use one of these be sure to always include the right collection in the where clause.
|
|
|
94 |
Ask me about fiboa data (here: all baltic states)!
|
95 |
Request "a map" to get map output, or table for tabular output, e.g.
|
96 |
|
97 |
+
- Show a map with the 10 largest sugar beet fields
|
|
|
|
|
98 |
- Show a map with the largest field in Estonia
|
99 |
+
- Show a table of the top ten crops
|
100 |
+
- What are the top ten crops that have a field size over 10 hectares?
|
101 |
+
- Compute the total area of all fields in km² and compute the percentage the total area of the baltic states (175015 km²)
|
102 |
|
103 |
'''
|
104 |
|
105 |
+
example = "Which are the 10 largest fields?"
|
106 |
with st.container():
|
107 |
if prompt := st.chat_input(example, key="chain"):
|
108 |
st.chat_message("user").write(prompt)
|
fiboa/query.py
CHANGED
@@ -8,7 +8,7 @@ from ibis import _
|
|
8 |
|
9 |
def execute_prompt(con, chain, prompt):
|
10 |
response = chain.invoke({"question": prompt})
|
11 |
-
st.write(response
|
12 |
gdf = as_geopandas(con, response)
|
13 |
|
14 |
if len(gdf) == 0:
|
@@ -28,8 +28,7 @@ def execute_prompt(con, chain, prompt):
|
|
28 |
})
|
29 |
|
30 |
def as_geopandas(con, response):
|
31 |
-
|
32 |
-
response = re.sub(";$", "", response).replace("testing", "crops")
|
33 |
sql_query = f"CREATE OR REPLACE VIEW testing AS ({response})"
|
34 |
con.raw_sql(sql_query)
|
35 |
gdf = con.table("testing")
|
@@ -48,4 +47,4 @@ def as_geopandas(con, response):
|
|
48 |
if dtype.startswith("datetime64"):
|
49 |
gdf[col] = gdf[col].astype(str)
|
50 |
|
51 |
-
return gdf
|
|
|
8 |
|
9 |
def execute_prompt(con, chain, prompt):
|
10 |
response = chain.invoke({"question": prompt})
|
11 |
+
st.write(response)
|
12 |
gdf = as_geopandas(con, response)
|
13 |
|
14 |
if len(gdf) == 0:
|
|
|
28 |
})
|
29 |
|
30 |
def as_geopandas(con, response):
|
31 |
+
response = re.sub(";$", "", response)
|
|
|
32 |
sql_query = f"CREATE OR REPLACE VIEW testing AS ({response})"
|
33 |
con.raw_sql(sql_query)
|
34 |
gdf = con.table("testing")
|
|
|
47 |
if dtype.startswith("datetime64"):
|
48 |
gdf[col] = gdf[col].astype(str)
|
49 |
|
50 |
+
return gdf
|
questions.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* What's the total area of devoted to agriculture in Latvia?
|
6 |
* Is the average field size larger in lithuania or latvia?
|
7 |
* How many fields are there that are under 1 hectare?
|
8 |
-
* Show a map with the 10
|
9 |
* What percent of fields are under 2 hectares?
|
10 |
* Show a map with the largest field in Estonia
|
11 |
* Show a map with the ten largest fields
|
@@ -18,6 +18,8 @@
|
|
18 |
|
19 |
|
20 |
|
|
|
|
|
21 |
## More coding / prompting needed
|
22 |
|
23 |
### Maps with more
|
|
|
5 |
* What's the total area of devoted to agriculture in Latvia?
|
6 |
* Is the average field size larger in lithuania or latvia?
|
7 |
* How many fields are there that are under 1 hectare?
|
8 |
+
* Show a map with the 10 largestfields
|
9 |
* What percent of fields are under 2 hectares?
|
10 |
* Show a map with the largest field in Estonia
|
11 |
* Show a map with the ten largest fields
|
|
|
18 |
|
19 |
|
20 |
|
21 |
+
|
22 |
+
|
23 |
## More coding / prompting needed
|
24 |
|
25 |
### Maps with more
|