rtferraz commited on
Commit
95d5651
·
verified ·
1 Parent(s): e58b50f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -3,7 +3,7 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
- import pandas as pd
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
- # Load the CSV file into a DataFrame
41
- df = pd.read_csv("data.csv", encoding="utf-8")
42
-
43
- # Filter the DataFrame to find rows where the CLIENTE column matches the username
44
- client_row = df[df["CLIENTE:"].str.strip().str.lower() == username.strip().lower()]
45
-
46
- # If no rows are found, return None
47
- if client_row.empty:
48
- return f"Didn't find any information for CLIENTE: {user_name}"
49
-
50
- # Return the row(s) as a dictionary (or DataFrame if preferred)
51
- return client_row.to_dict(orient="records")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: