Spaces:
Sleeping
Sleeping
# App.py to launch the app via hugging face | |
####################################################################################################### | |
# IMPORT | |
####################################################################################################### | |
import pandas as pd | |
import geopandas as gpd | |
import os | |
from configparser import ConfigParser | |
import gradio as gr | |
# modules | |
from modules.geojson_github_loader import download_github_geojson | |
from modules.geojson_processor import geojson_processor_to_csv | |
from modules.language_model import TAPAS | |
####################################################################################################### | |
# CONFIG | |
####################################################################################################### | |
# Prints disabled!! | |
#print('\nCurrent Working Directory (CWD):\n' + os.getcwd()) | |
config_object = ConfigParser() | |
if 'config.ini' in os.listdir(): | |
config_object.read('config.ini') | |
#print('Setting have been imported from the config file.') | |
else: | |
print('No config file in the CWD') | |
quit() | |
# changing CWD and input output folders | |
os.chdir(format(config_object['CONFIG']['CWD'])) | |
DATA = os.getcwd() + '\\' + format(config_object['CONFIG']['Input']) | |
OUT = os.getcwd() + '\\' + format(config_object['CONFIG']['Output']) | |
TEMP = os.getcwd() + '\\' + format(config_object['CONFIG']['Temp']) | |
####################################################################################################### | |
# Load and prepare Data | |
####################################################################################################### | |
# load github data | |
# attributes | |
github_user = "Giedeon25" | |
github_repo = "GID-Project" | |
file_path_github = "main/data/Input/gadm41_DEU_1.json" | |
token = "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" | |
local_file_path = DATA + '\\' + 'gadm41_DEU_1.json' | |
output_file = TEMP + '\\' + 'gadm41_DEU_1' | |
# load locally | |
geojson_data = gpd.read_file(local_file_path) | |
####################################################################################################### | |
# LLM | |
####################################################################################################### | |
# attributes | |
question = 'what is the geometry of Saxony?' | |
table_main = pd.read_csv(TEMP + '\\' + 'gadm41_DEU_1_main').astype(str) | |
table_geom = pd.read_csv(TEMP + '\\' + 'gadm41_DEU_1_geom') | |
# function | |
TAPAS(question, table_main) | |
################################################################################## | |
# Function that enables testing | |
################################################################################## | |
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(TEMP + '\\' + 'gadm41_DEU_1_main').astype(str) | |
blub = str(AskAI(ques,1,Tmain)) | |
return(blub) | |
####################################################################################### | |
# Gradio Interface | |
############################################################################### | |
desc = 'Example: What is the geometry of Saxony?' | |
iface = gr.Interface(fn=AskAI_easy, inputs=['text'], outputs='text', description= desc) | |
iface.launch() |