Spaces:
Running
Running
# 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() | |
# |