atifsial123 commited on
Commit
6258046
1 Parent(s): a8a39fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -59,7 +59,7 @@ def format_output(details):
59
  return html
60
 
61
  # Function to add or update details
62
- def add_or_update_details(name, phone_number):
63
  try:
64
  # Load the existing data
65
  df = load_dataset()
@@ -70,14 +70,18 @@ def add_or_update_details(name, phone_number):
70
  details = get_details(name, df)
71
 
72
  if details:
73
- # Update the phone number
74
  df.loc[df['Name'].str.lower() == name.strip().lower(), 'Contact Number (Whatsapp)'] = phone_number
75
- message = "Phone number updated successfully."
 
 
76
  else:
77
  # Add a new entry if the name was not found
78
  new_entry = {
79
  'Name': name,
80
  'Contact Number (Whatsapp)': phone_number,
 
 
81
  # Add other fields with default values as needed
82
  }
83
  df = df.append(new_entry, ignore_index=True)
@@ -92,7 +96,7 @@ def add_or_update_details(name, phone_number):
92
  return f"Error: {e}"
93
 
94
  # Combine the functions to create a prediction and update functionality
95
- def predict_and_update(name, phone_number=None):
96
  try:
97
  # Load the dataset from the provided file path
98
  df = load_dataset()
@@ -103,9 +107,9 @@ def predict_and_update(name, phone_number=None):
103
  details = get_details(name, df)
104
  details_html = format_output(details)
105
 
106
- # If a phone number is provided, update or add the details
107
- if phone_number:
108
- update_message = add_or_update_details(name, phone_number)
109
  return f"{details_html}<br><br>{update_message}"
110
  else:
111
  return details_html
@@ -118,14 +122,15 @@ iface = gr.Interface(
118
  fn=predict_and_update,
119
  inputs=[
120
  gr.Textbox(lines=1, label="**Enter Name**"),
121
- gr.Textbox(lines=1, label="**Phone Number** (Optional - to add/update)")
 
 
122
  ],
123
  outputs="html",
124
  title="Name Details Lookup and Update",
125
- description="Enter a name to find all details associated with it from the 'cleaned_data.xlsx' file. Optionally, add or update the phone number."
126
  )
127
 
128
  # Run the Gradio interface
129
  if __name__ == "__main__":
130
  iface.launch()
131
-
 
59
  return html
60
 
61
  # Function to add or update details
62
+ def add_or_update_details(name, phone_number, current_occupation, pass_out_year):
63
  try:
64
  # Load the existing data
65
  df = load_dataset()
 
70
  details = get_details(name, df)
71
 
72
  if details:
73
+ # Update the phone number, current occupation, and pass out year
74
  df.loc[df['Name'].str.lower() == name.strip().lower(), 'Contact Number (Whatsapp)'] = phone_number
75
+ df.loc[df['Name'].str.lower() == name.strip().lower(), 'Current Occupation'] = current_occupation
76
+ df.loc[df['Name'].str.lower() == name.strip().lower(), 'Pass Out Year'] = pass_out_year
77
+ message = "Phone number, occupation, and pass out year updated successfully."
78
  else:
79
  # Add a new entry if the name was not found
80
  new_entry = {
81
  'Name': name,
82
  'Contact Number (Whatsapp)': phone_number,
83
+ 'Current Occupation': current_occupation,
84
+ 'Pass Out Year': pass_out_year,
85
  # Add other fields with default values as needed
86
  }
87
  df = df.append(new_entry, ignore_index=True)
 
96
  return f"Error: {e}"
97
 
98
  # Combine the functions to create a prediction and update functionality
99
+ def predict_and_update(name, phone_number=None, current_occupation=None, pass_out_year=None):
100
  try:
101
  # Load the dataset from the provided file path
102
  df = load_dataset()
 
107
  details = get_details(name, df)
108
  details_html = format_output(details)
109
 
110
+ # If a phone number, current occupation, or pass out year is provided, update or add the details
111
+ if phone_number or current_occupation or pass_out_year:
112
+ update_message = add_or_update_details(name, phone_number, current_occupation, pass_out_year)
113
  return f"{details_html}<br><br>{update_message}"
114
  else:
115
  return details_html
 
122
  fn=predict_and_update,
123
  inputs=[
124
  gr.Textbox(lines=1, label="**Enter Name**"),
125
+ gr.Textbox(lines=1, label="**Phone Number** (Optional - to add/update)"),
126
+ gr.Textbox(lines=1, label="**Current Occupation** (Optional - to add/update)"),
127
+ gr.Textbox(lines=1, label="**Pass Out Year** (Optional - to add/update)")
128
  ],
129
  outputs="html",
130
  title="Name Details Lookup and Update",
131
+ description="Enter a name to find all details associated with it from the 'cleaned_data.xlsx' file. Optionally, add or update the phone number, current occupation, and pass out year."
132
  )
133
 
134
  # Run the Gradio interface
135
  if __name__ == "__main__":
136
  iface.launch()