GID_HuggingFace / modules /gradio_testing.py
giho905e's picture
Upload 30 files
84e78bb
raw
history blame
No virus
2.25 kB
# Import
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)
def getLand(landnr):
landnr = int(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 = gpd.GeoDataFrame(data)
landR = gdf.iloc[landnr]
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):
land = getLand(landnr)
kuerzel = getCountrycode(land)
return str(kuerzel)
#'''
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=grad_Country, inputs="number", outputs="text")
if __name__ == '__main__':
iface.launch()
#'''