OpenTest / app.py
giho905e's picture
Update app.py
d77183b
raw
history blame
2.62 kB
# Import
import gradio
import geopandas as gpd
# Sample DataFrame acording to actual structure (use your own data)
data = {'GID_1': ['DEU.1_1','DEU.2_1'],
'GID_0': ['DEU', 'DEU'],
'COUNTRY': ['Germany', 'Germany'],
'NAME_1': ['Baden-Würtenberg', 'Bayern'],
'VARNAME_1': ['NA','Bavaria'],
'NL_NAME_1': ['NA', 'NA'],
'TYPE_1': ['Land', 'Freistaat'],
'ENGTYPE_1': ['State', 'Freestate'],
'CC_1': ['08','09'],
'HASC_1': ['DE.BW', 'DE.BY'], # Extra for subnational countys (https://de.wikipedia.org/wiki/Hierarchical_administrative_subdivision_codes)
'ISO_1': ['NA', 'DE-BY'], # International Order --> Check First (https://de.wikipedia.org/wiki/ISO_3166)
'geometry': [0,1]
}
gdf = gpd.GeoDataFrame(data)
# function to generate output
# Land should be a line from the geojson-table
# Currently only works for NUTS-1 areas!!!
def getCountrycode(land, level):
iso = 'ISO_'+ str(level)
hasc = 'HASC_' + str(level)
if land[iso] != 'NA':
return land[iso]
elif land[hasc]:
return land[hasc]
else:
return False
blub = gdf.iloc[0]
import pandas as pd
def getLand(landnr):
#Test
data = {'GID_1': ['DEU.1_1','DEU.2_1'],
'GID_0': ['DEU', 'DEU'],
'COUNTRY': ['Germany', 'Germany'],
'NAME_1': ['Baden-Würtenberg', 'Bayern'],
'VARNAME_1': ['NA','Bavaria'],
'NL_NAME_1': ['NA', 'NA'],
'TYPE_1': ['Land', 'Freistaat'],
'ENGTYPE_1': ['State', 'Freestate'],
'CC_1': ['08','09'],
'HASC_1': ['DE.BW', 'DE.BY'], # Extra for subnational countys (https://de.wikipedia.org/wiki/Hierarchical_administrative_subdivision_codes)
'ISO_1': ['NA', 'DE-BY'], # International Order --> Check First (https://de.wikipedia.org/wiki/ISO_3166)
'geometry': [0,1]
}
gdf = pd.DataFrame(data)
landR = gdf.iloc[landnr]
#print(landR)
return landR
# function to generate output
# Land should be a line from the geojson-table
# Currently only works for NUTS-1 areas!!!
def getCountrycode(land, level = 1):
iso = 'ISO_'+ str(level)
hasc = 'HASC_' + str(level)
if land[iso] != 'NA':
return str(land[iso])
elif land[hasc]:
return str(land[hasc])
else:
return False
def grad_Country(landnr):
landnr = int(landnr)
land = getLand(int(landnr))
kuerzel = getCountrycode(land)
return str(kuerzel)
# Gradio
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()