Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,6 +82,7 @@ docstatus = ""
|
|
| 82 |
sample_table = ""
|
| 83 |
#This is to define the summary of the runtime tool. This summary will be updated in prompt template and description of the new tool
|
| 84 |
run_time_tool_summary=""
|
|
|
|
| 85 |
|
| 86 |
# Define global variables for managing the thread and current_event
|
| 87 |
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
|
@@ -845,6 +846,8 @@ def handle_dislike(data: gr.LikeData):
|
|
| 845 |
|
| 846 |
# greet with user name on successful login
|
| 847 |
def update_message(request: gr.Request):
|
|
|
|
|
|
|
| 848 |
return f"<h2 style=' font-family: Calibri;'>Welcome, {request.username}</h4>"
|
| 849 |
|
| 850 |
# Function to generate a 50-word summary of the newly uploaded doc using OpenAI
|
|
@@ -1174,8 +1177,8 @@ def handle_large_dataset(df, create_document,isDataFrame):
|
|
| 1174 |
current_folder = os.getcwd()
|
| 1175 |
|
| 1176 |
|
| 1177 |
-
|
| 1178 |
-
file_path = os.path.join(current_folder, 'output_data.xlsx')
|
| 1179 |
df.to_excel(file_path, index=False)
|
| 1180 |
|
| 1181 |
|
|
@@ -1211,14 +1214,23 @@ def handle_large_dataset(df, create_document,isDataFrame):
|
|
| 1211 |
def create_file_HF(file_path):
|
| 1212 |
from huggingface_hub import create_branch, create_tag
|
| 1213 |
from huggingface_hub import login
|
| 1214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1215 |
login(token=os.getenv("HF_TOKEN"))
|
| 1216 |
#create_branch("Redmind/NewageNXTGPT_Repo_trial", repo_type="space", branch="test-branch")
|
| 1217 |
|
| 1218 |
#create_tag("bigcode/the-stack", repo_type="dataset", revision="v0.1-release", tag="v0.1.1", tag_message="Bump release version.")
|
| 1219 |
|
| 1220 |
-
|
| 1221 |
-
api = HfApi()
|
| 1222 |
api.upload_file(path_or_fileobj=file_path, repo_id="Redmind/NewageNXTGPT_Repo_trial",revision = "test-branch", repo_type= "space", path_in_repo='output_data.xlsx')
|
| 1223 |
|
| 1224 |
|
|
@@ -1243,7 +1255,17 @@ def create_pdf(cname,ename,account_number):
|
|
| 1243 |
api = HfApi()
|
| 1244 |
#api.upload_file(path_or_fileobj=output_file_name, repo_id=repo_id, repo_type= "space", path_in_repo=file_output)
|
| 1245 |
return f"{output_file_name} is created successfully."
|
| 1246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1247 |
|
| 1248 |
css = """
|
| 1249 |
|
|
|
|
| 82 |
sample_table = ""
|
| 83 |
#This is to define the summary of the runtime tool. This summary will be updated in prompt template and description of the new tool
|
| 84 |
run_time_tool_summary=""
|
| 85 |
+
user_name = ""
|
| 86 |
|
| 87 |
# Define global variables for managing the thread and current_event
|
| 88 |
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
|
|
|
| 846 |
|
| 847 |
# greet with user name on successful login
|
| 848 |
def update_message(request: gr.Request):
|
| 849 |
+
global user_name
|
| 850 |
+
user_name = request.username
|
| 851 |
return f"<h2 style=' font-family: Calibri;'>Welcome, {request.username}</h4>"
|
| 852 |
|
| 853 |
# Function to generate a 50-word summary of the newly uploaded doc using OpenAI
|
|
|
|
| 1177 |
current_folder = os.getcwd()
|
| 1178 |
|
| 1179 |
|
| 1180 |
+
file_path = "output_data.xlsx"
|
| 1181 |
+
#file_path = os.path.join(current_folder, 'output_data.xlsx')
|
| 1182 |
df.to_excel(file_path, index=False)
|
| 1183 |
|
| 1184 |
|
|
|
|
| 1214 |
def create_file_HF(file_path):
|
| 1215 |
from huggingface_hub import create_branch, create_tag
|
| 1216 |
from huggingface_hub import login
|
| 1217 |
+
from huggingface_hub import HfApi
|
| 1218 |
+
api = HfApi()
|
| 1219 |
+
global user_name
|
| 1220 |
+
repo_id = "Redmind/NewageNXTGPT_Repo_trial"
|
| 1221 |
+
directory = user_name
|
| 1222 |
+
token = os.getenv("HF_TOKEN")
|
| 1223 |
+
#check if direcotry exists
|
| 1224 |
+
dir_exists_flag = directory_exists(repo_id, directory, token)
|
| 1225 |
+
if not dir_exists_flag:
|
| 1226 |
+
file_path = directory + "/" + file_path
|
| 1227 |
+
#if directory does not exist, create the directoty
|
| 1228 |
login(token=os.getenv("HF_TOKEN"))
|
| 1229 |
#create_branch("Redmind/NewageNXTGPT_Repo_trial", repo_type="space", branch="test-branch")
|
| 1230 |
|
| 1231 |
#create_tag("bigcode/the-stack", repo_type="dataset", revision="v0.1-release", tag="v0.1.1", tag_message="Bump release version.")
|
| 1232 |
|
| 1233 |
+
|
|
|
|
| 1234 |
api.upload_file(path_or_fileobj=file_path, repo_id="Redmind/NewageNXTGPT_Repo_trial",revision = "test-branch", repo_type= "space", path_in_repo='output_data.xlsx')
|
| 1235 |
|
| 1236 |
|
|
|
|
| 1255 |
api = HfApi()
|
| 1256 |
#api.upload_file(path_or_fileobj=output_file_name, repo_id=repo_id, repo_type= "space", path_in_repo=file_output)
|
| 1257 |
return f"{output_file_name} is created successfully."
|
| 1258 |
+
|
| 1259 |
+
|
| 1260 |
+
def directory_exists(repo_id, directory, token):
|
| 1261 |
+
try:
|
| 1262 |
+
# List all files in the repository
|
| 1263 |
+
files = api.list_repo_files(repo_id=repo_id, repo_type="space", token=token)
|
| 1264 |
+
# Check if any file starts with the directory path
|
| 1265 |
+
return any(file.startswith(directory) for file in files)
|
| 1266 |
+
except Exception as e:
|
| 1267 |
+
print(f"Error checking directory existence: {e}")
|
| 1268 |
+
return False
|
| 1269 |
|
| 1270 |
css = """
|
| 1271 |
|