Spaces:
Sleeping
Sleeping
File size: 2,532 Bytes
84e78bb 4cbe8a4 666371e 84e78bb 08cb5a1 b2c9716 84e78bb b2c9716 76f2dc1 b2c9716 76f2dc1 b2c9716 76f2dc1 b2c9716 76f2dc1 8d5110b 1ca3ffc 2e62286 84e78bb c05833d 84e78bb 0304ca7 899d28f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# App.py to launch the app via hugging face
#######################################################################################################
# IMPORT
#######################################################################################################
import pandas as pd
import gradio as gr
# modules
from modules.language_model import TAPAS
##################################################################################
# Function that enables testing
##################################################################################
table_main = pd.read_csv('gadm41_DEU_1_main').astype(str)
def AskAI(ques, lv, table_main = table_main):
level = int(lv) # Currently placeholder
question = str(ques)
ans = TAPAS(question = question, table_main= table_main)
return(ans)
def AskAI_easy(ques):
Tmain = pd.read_csv('gadm41_DEU_1_main').astype(str)
Tgeom = pd.read_csv('gadm41_DEU_1_geom').astype(str)
fname = ''.join(char for char in str(ques) if char.isupper() or char.islower())
blub = str(AskAI(ques,1,Tmain))
# generate DL Links ###################################
# Geospatial Libraries
import geopandas as gpd
from shapely.wkt import loads
row = eval(blub)[0]['coordinates'][0][0] #get object
out_df = Tmain.iloc[row,:12]
out_df['geometry'] = Tgeom.iloc[row,1]
geometry_wkt = out_df['geometry']
geometry = loads(geometry_wkt)
out_gdf = gpd.GeoDataFrame(geometry=[geometry]) #
geojson_string = out_gdf.to_json()
# store File on GitHub
from github import Github
from github import Auth
github_user = "Giedeon25"
github_repo = "GID-Project"
token = "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"
# using an access token
auth = Auth.Token("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")
# First create a Github instance:
g = Github(auth=auth)
repo = g.get_repo("Giedeon25/GID-Project")
repo.create_file("data/Output/" + fname + ".json", "committing file", geojson_string, branch="main") # create File
return(blub + " ==== " + "dllink: https://github.com/Giedeon25/GID-Project/blob/main/data/Output/" + fname + ".json")
#######################################################################################
# Gradio Interface
###############################################################################
desc = 'Example: What is the Bundesland with tyhe biggest Area?'
iface = gr.Interface(fn=AskAI_easy, inputs=['text'], outputs='text', description= desc)
iface.launch()
# |