Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,7 +70,9 @@ import base64
|
|
| 70 |
|
| 71 |
#for PDF form filling
|
| 72 |
from PyPDFForm import FormWrapper
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
import os
|
| 75 |
|
| 76 |
import zipfile
|
|
@@ -102,12 +104,10 @@ os.environ["LANGFUSE_HOST"] = os.getenv("LANGFUSE_HOST")
|
|
| 102 |
|
| 103 |
DB_USER = 'u852023448_redmindgpt'
|
| 104 |
DB_PASSWORD = 'redmindGpt@123'
|
| 105 |
-
DB_HOST = '
|
| 106 |
DB_NAME = 'u852023448_redmindgpt'
|
| 107 |
|
| 108 |
-
|
| 109 |
-
from huggingface_hub import login
|
| 110 |
-
from huggingface_hub import HfApi
|
| 111 |
api= HfApi()
|
| 112 |
token = os.getenv("HF_TOKEN")
|
| 113 |
login(token=os.getenv("HF_TOKEN"))
|
|
@@ -117,7 +117,7 @@ langfuse_handler.auth_check() # Optional: Checks if the authentication is succe
|
|
| 117 |
|
| 118 |
nltk.download('punkt')
|
| 119 |
|
| 120 |
-
open_api_key_token = os.getenv("
|
| 121 |
|
| 122 |
os.environ['OPENAI_API_KEY'] = open_api_key_token
|
| 123 |
pdf_path = "Input/Inbound.pdf"
|
|
@@ -136,13 +136,13 @@ inventory_date = datetime.today().strftime('%Y-%m-%d')
|
|
| 136 |
apis = [
|
| 137 |
# fetch warehouse ID
|
| 138 |
{
|
| 139 |
-
"url": "http://193.203.162.39:
|
| 140 |
-
"params": {"query":
|
| 141 |
},
|
| 142 |
|
| 143 |
# Stock summary based on warehouse id
|
| 144 |
{
|
| 145 |
-
"url": "http://193.203.162.39:
|
| 146 |
"params": {"branchId": 343, "onDate": inventory_date, "warehouseId": warehouse_id}
|
| 147 |
}
|
| 148 |
]
|
|
@@ -396,6 +396,10 @@ def make_api_request(url, params):
|
|
| 396 |
"""Generic function to make API GET requests and return JSON data."""
|
| 397 |
try:
|
| 398 |
response = requests.get(url, params=params)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
response.raise_for_status() # Raises an HTTPError if the response was an error
|
| 400 |
return response.json() # Return the parsed JSON data
|
| 401 |
except requests.exceptions.HTTPError as http_err:
|
|
@@ -414,15 +418,17 @@ def inventory_report(question):
|
|
| 414 |
print(f"Warehouse: {warehouse_name}, Email: {user_email}, Question: {user_question}")
|
| 415 |
else:
|
| 416 |
return "warehouse name not found"
|
| 417 |
-
|
|
|
|
|
|
|
| 418 |
data = make_api_request(apis[0]["url"], apis[0]["params"])
|
| 419 |
-
print(data)
|
| 420 |
if data:
|
| 421 |
-
|
| 422 |
# Extracting the id for the warehouse with the name "WH"
|
| 423 |
-
warehouse_id = next((item['id'] for item in data['result'] if item['
|
| 424 |
print(f"warehouse_id:{warehouse_id}")
|
| 425 |
-
if
|
| 426 |
print("before api id")
|
| 427 |
# Step 3: Update the placeholder with the actual warehouse_id
|
| 428 |
for api in apis:
|
|
@@ -434,32 +440,41 @@ def inventory_report(question):
|
|
| 434 |
print(apis)
|
| 435 |
data1 = make_api_request(apis[1]["url"], apis[1]["params"])
|
| 436 |
print(data1)
|
| 437 |
-
if
|
| 438 |
headers = ["S.No", "Warehouse Code", "Warehouse Name", "Customer Code", "Customer Name", "Item Code", "Item Name",
|
| 439 |
"Currency", "EAN", "UOM", "Quantity", "Gross Weight", "Volume", "Total Value"]
|
| 440 |
table_data = []
|
| 441 |
|
| 442 |
-
# Check if 'content'
|
| 443 |
-
if data1['result']
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
else:
|
|
|
|
|
|
|
| 463 |
print("No data available in 'content'.")
|
| 464 |
return "There are no inventory details for the warehouse you have given."
|
| 465 |
|
|
@@ -1117,17 +1132,23 @@ def chat_with_excel_data_dataframe(question):
|
|
| 1117 |
if isinstance(response_dataframe, pd.DataFrame) == False:
|
| 1118 |
|
| 1119 |
print("The result is not a DataFrame.")
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1123 |
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
|
| 1127 |
-
|
| 1128 |
-
|
|
|
|
|
|
|
|
|
|
| 1129 |
|
| 1130 |
-
|
| 1131 |
#handle large dataset
|
| 1132 |
response = handle_large_dataset(response_dataframe, create_document,isDataFrame)
|
| 1133 |
|
|
@@ -1261,7 +1282,7 @@ def create_file_HF(file_path,directory,document_created = False):
|
|
| 1261 |
repo_id = "Redmind/NewageNXTGPT_Repo_trial"
|
| 1262 |
|
| 1263 |
|
| 1264 |
-
if
|
| 1265 |
directory = directory + "/" + "document"
|
| 1266 |
document_created = False
|
| 1267 |
#check if direcotry exists
|
|
@@ -1439,8 +1460,8 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
| 1439 |
sample_button = gr.Button("What are the details of ASN24091600002", elem_classes="gr-buttonbig")
|
| 1440 |
sample_button1 = gr.Button("What are the active warehouses available", elem_classes="gr-buttonbig")
|
| 1441 |
sample_button2 = gr.Button("Explain Pre-Receiving Yard Management", elem_classes="gr-buttonbig")
|
| 1442 |
-
sample_button3 = gr.Button("can you generate a doughnut chart with item name and quantities for warehouse
|
| 1443 |
-
sample_button4 = gr.Button("Analyze item name & quantity for different customers in a stacked bar chart for the warehouse
|
| 1444 |
|
| 1445 |
# Chatbot component
|
| 1446 |
with gr.Row():
|
|
|
|
| 70 |
|
| 71 |
#for PDF form filling
|
| 72 |
from PyPDFForm import FormWrapper
|
| 73 |
+
from huggingface_hub import create_branch, create_tag
|
| 74 |
+
from huggingface_hub import login
|
| 75 |
+
from huggingface_hub import HfApi
|
| 76 |
import os
|
| 77 |
|
| 78 |
import zipfile
|
|
|
|
| 104 |
|
| 105 |
DB_USER = 'u852023448_redmindgpt'
|
| 106 |
DB_PASSWORD = 'redmindGpt@123'
|
| 107 |
+
DB_HOST = 'srv1110.hstgr.io'
|
| 108 |
DB_NAME = 'u852023448_redmindgpt'
|
| 109 |
|
| 110 |
+
|
|
|
|
|
|
|
| 111 |
api= HfApi()
|
| 112 |
token = os.getenv("HF_TOKEN")
|
| 113 |
login(token=os.getenv("HF_TOKEN"))
|
|
|
|
| 117 |
|
| 118 |
nltk.download('punkt')
|
| 119 |
|
| 120 |
+
open_api_key_token = os.getenv("OPENAI_API_KEY")
|
| 121 |
|
| 122 |
os.environ['OPENAI_API_KEY'] = open_api_key_token
|
| 123 |
pdf_path = "Input/Inbound.pdf"
|
|
|
|
| 136 |
apis = [
|
| 137 |
# fetch warehouse ID
|
| 138 |
{
|
| 139 |
+
"url": "http://193.203.162.39:8383/nxt-wms/userWarehouse/fetchWarehouseForUserId?",
|
| 140 |
+
"params": {"query": '', "userId": 164}
|
| 141 |
},
|
| 142 |
|
| 143 |
# Stock summary based on warehouse id
|
| 144 |
{
|
| 145 |
+
"url": "http://193.203.162.39:8383/nxt-wms/transactionHistory/stockSummary?",
|
| 146 |
"params": {"branchId": 343, "onDate": inventory_date, "warehouseId": warehouse_id}
|
| 147 |
}
|
| 148 |
]
|
|
|
|
| 396 |
"""Generic function to make API GET requests and return JSON data."""
|
| 397 |
try:
|
| 398 |
response = requests.get(url, params=params)
|
| 399 |
+
print("url:",url)
|
| 400 |
+
print("params:",params)
|
| 401 |
+
print("response:",response)
|
| 402 |
+
print(response.status_code)
|
| 403 |
response.raise_for_status() # Raises an HTTPError if the response was an error
|
| 404 |
return response.json() # Return the parsed JSON data
|
| 405 |
except requests.exceptions.HTTPError as http_err:
|
|
|
|
| 418 |
print(f"Warehouse: {warehouse_name}, Email: {user_email}, Question: {user_question}")
|
| 419 |
else:
|
| 420 |
return "warehouse name not found"
|
| 421 |
+
print(f"warehouse name: {warehouse_name}")
|
| 422 |
+
apis[0]["params"]["query"] = warehouse_name
|
| 423 |
+
print(apis[0]["params"])
|
| 424 |
data = make_api_request(apis[0]["url"], apis[0]["params"])
|
| 425 |
+
print("Warehouse data:",data)
|
| 426 |
if data:
|
| 427 |
+
|
| 428 |
# Extracting the id for the warehouse with the name "WH"
|
| 429 |
+
warehouse_id = next((item['id'] for item in data['result'] if item['name'] == warehouse_name), None)
|
| 430 |
print(f"warehouse_id:{warehouse_id}")
|
| 431 |
+
if warehouse_id:
|
| 432 |
print("before api id")
|
| 433 |
# Step 3: Update the placeholder with the actual warehouse_id
|
| 434 |
for api in apis:
|
|
|
|
| 440 |
print(apis)
|
| 441 |
data1 = make_api_request(apis[1]["url"], apis[1]["params"])
|
| 442 |
print(data1)
|
| 443 |
+
if data1:
|
| 444 |
headers = ["S.No", "Warehouse Code", "Warehouse Name", "Customer Code", "Customer Name", "Item Code", "Item Name",
|
| 445 |
"Currency", "EAN", "UOM", "Quantity", "Gross Weight", "Volume", "Total Value"]
|
| 446 |
table_data = []
|
| 447 |
|
| 448 |
+
# Check if 'result' and 'content' exist and have valid types
|
| 449 |
+
if 'result' in data1 and isinstance(data1['result'], dict):
|
| 450 |
+
result = data1['result']
|
| 451 |
+
if 'content' in result and isinstance(result['content'], list):
|
| 452 |
+
for index, item in enumerate(result['content'], start=1):
|
| 453 |
+
try:
|
| 454 |
+
row = [
|
| 455 |
+
index, # Serial number
|
| 456 |
+
item['warehouse']['code'],
|
| 457 |
+
item['warehouse']['name'],
|
| 458 |
+
item['customer']['code'],
|
| 459 |
+
item['customer']['name'],
|
| 460 |
+
item['skuMaster']['code'],
|
| 461 |
+
item['skuMaster']['name'],
|
| 462 |
+
item['currency']['code'],
|
| 463 |
+
item['eanUpc'],
|
| 464 |
+
item['uom']['code'],
|
| 465 |
+
item['totalQty'],
|
| 466 |
+
item['grossWeight'],
|
| 467 |
+
item['volume'],
|
| 468 |
+
item['totalValue']
|
| 469 |
+
]
|
| 470 |
+
table_data.append(row)
|
| 471 |
+
except KeyError as e:
|
| 472 |
+
print(f"Missing Key Error for item: {item} - {e}")
|
| 473 |
+
else:
|
| 474 |
+
print("Content is either missing or not a list:", result.get('content'))
|
| 475 |
else:
|
| 476 |
+
print("Result key is missing or not a dictionary in data1:", data1.get('result'))
|
| 477 |
+
|
| 478 |
print("No data available in 'content'.")
|
| 479 |
return "There are no inventory details for the warehouse you have given."
|
| 480 |
|
|
|
|
| 1132 |
if isinstance(response_dataframe, pd.DataFrame) == False:
|
| 1133 |
|
| 1134 |
print("The result is not a DataFrame.")
|
| 1135 |
+
print(str.lower("No employee details") not in response_dataframe)
|
| 1136 |
+
if str.lower("No employee details") not in str.lower(response_dataframe):
|
| 1137 |
+
if ":" in response_dataframe:
|
| 1138 |
+
|
| 1139 |
+
print("The result is a list of names.")
|
| 1140 |
+
isDataFrame = False
|
| 1141 |
+
names_part = response_dataframe.split(":", 1)[1] # Get everything after the colon and space
|
| 1142 |
|
| 1143 |
+
# Split the names by commas to create a list
|
| 1144 |
+
names = names_part.split(",")
|
| 1145 |
|
| 1146 |
+
# Convert the list of names to a DataFrame
|
| 1147 |
+
response_dataframe = pd.DataFrame(names, columns=["Result"])
|
| 1148 |
+
else:
|
| 1149 |
+
print("The result is a message.")
|
| 1150 |
+
return response_dataframe
|
| 1151 |
|
|
|
|
| 1152 |
#handle large dataset
|
| 1153 |
response = handle_large_dataset(response_dataframe, create_document,isDataFrame)
|
| 1154 |
|
|
|
|
| 1282 |
repo_id = "Redmind/NewageNXTGPT_Repo_trial"
|
| 1283 |
|
| 1284 |
|
| 1285 |
+
if document_created:
|
| 1286 |
directory = directory + "/" + "document"
|
| 1287 |
document_created = False
|
| 1288 |
#check if direcotry exists
|
|
|
|
| 1460 |
sample_button = gr.Button("What are the details of ASN24091600002", elem_classes="gr-buttonbig")
|
| 1461 |
sample_button1 = gr.Button("What are the active warehouses available", elem_classes="gr-buttonbig")
|
| 1462 |
sample_button2 = gr.Button("Explain Pre-Receiving Yard Management", elem_classes="gr-buttonbig")
|
| 1463 |
+
sample_button3 = gr.Button("can you generate a doughnut chart with item name and quantities for warehouse DUBAIWARE", elem_classes="gr-buttonbig")
|
| 1464 |
+
sample_button4 = gr.Button("Analyze item name & quantity for different customers in a stacked bar chart for the warehouse DUBAIWARE & send email to meetarun@gmail.com", elem_classes="gr-button")
|
| 1465 |
|
| 1466 |
# Chatbot component
|
| 1467 |
with gr.Row():
|