Spaces:
Sleeping
Sleeping
File size: 3,295 Bytes
84e78bb |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# 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() |