giho905e commited on
Commit
da901ac
·
1 Parent(s): aeb392c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import
2
+ import gradio
3
+ import geopandas as gpd
4
+
5
+ # Sample DataFrame acording to actual structure (use your own data)
6
+ data = {'GID_1': ['DEU.1_1','DEU.2_1'],
7
+ 'GID_0': ['DEU', 'DEU'],
8
+ 'COUNTRY': ['Germany', 'Germany'],
9
+ 'NAME_1': ['Baden-Würtenberg', 'Bayern'],
10
+ 'VARNAME_1': ['NA','Bavaria'],
11
+ 'NL_NAME_1': ['NA', 'NA'],
12
+ 'TYPE_1': ['Land', 'Freistaat'],
13
+ 'ENGTYPE_1': ['State', 'Freestate'],
14
+ 'CC_1': ['08','09'],
15
+ 'HASC_1': ['DE.BW', 'DE.BY'], # Extra for subnational countys (https://de.wikipedia.org/wiki/Hierarchical_administrative_subdivision_codes)
16
+ 'ISO_1': ['NA', 'DE-BY'], # International Order --> Check First (https://de.wikipedia.org/wiki/ISO_3166)
17
+ 'geometry': [0,1]
18
+ }
19
+ gdf = gpd.GeoDataFrame(data)
20
+
21
+ # function to generate output
22
+ # Land should be a line from the geojson-table
23
+ # Currently only works for NUTS-1 areas!!!
24
+
25
+ def getCountrycode(land, level):
26
+ iso = 'ISO_'+ str(level)
27
+ hasc = 'HASC_' + str(level)
28
+ if land[iso] != 'NA':
29
+ return land[iso]
30
+ elif land[hasc]:
31
+ return land[hasc]
32
+ else:
33
+ return False
34
+
35
+ blub = gdf.iloc[0]
36
+
37
+ bay_cc = getCountrycode(blub,1)
38
+ # Testing
39
+ print(bay_cc)
40
+
41
+ # Gradio
42
+ import gradio as gr
43
+
44
+ def greet(name):
45
+ return "Hello " + name + "!!"
46
+
47
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
48
+ iface.launch()