Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
-
import
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
|
@@ -37,18 +37,33 @@ def get_user_row(user_name: str) -> str:
|
|
| 37 |
user_name: A string that's the user name.
|
| 38 |
"""
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
@tool
|
| 54 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import csv
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
|
|
|
| 37 |
user_name: A string that's the user name.
|
| 38 |
"""
|
| 39 |
|
| 40 |
+
try:
|
| 41 |
+
# Open the CSV file
|
| 42 |
+
with open("data.csv", mode="r", encoding="utf-8") as file:
|
| 43 |
+
reader = csv.DictReader(file, delimiter=",")
|
| 44 |
+
|
| 45 |
+
# Initialize a list to store matching rows
|
| 46 |
+
matching_rows = []
|
| 47 |
+
|
| 48 |
+
# Iterate through each row in the CSV
|
| 49 |
+
for row in reader:
|
| 50 |
+
# Check if the CLIENTE column matches the username (case-insensitive and stripped of whitespace)
|
| 51 |
+
if row["CLIENTE:"].strip().lower() == username.strip().lower():
|
| 52 |
+
matching_rows.append(row)
|
| 53 |
+
|
| 54 |
+
# If no matching rows are found, return None
|
| 55 |
+
if not matching_rows:
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
+
# Return the matching rows
|
| 59 |
+
return matching_rows
|
| 60 |
+
|
| 61 |
+
except FileNotFoundError:
|
| 62 |
+
return "Error: The file 'data.csv' was not found."
|
| 63 |
+
except KeyError:
|
| 64 |
+
return "Error: The 'CLIENTE:' column is missing in the CSV file."
|
| 65 |
+
except Exception as e:
|
| 66 |
+
return f"An unexpected error occurred: {e}"
|
| 67 |
|
| 68 |
@tool
|
| 69 |
def get_current_time_in_timezone(timezone: str) -> str:
|