Rathapoom commited on
Commit
24efe9b
Β·
verified Β·
1 Parent(s): 8367b0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -36
app.py CHANGED
@@ -72,69 +72,68 @@ Purpose: Monthly performance review and staff allocation planning.
72
  # Function to format user-friendly summaries
73
  def format_user_summary(analysis_result):
74
  """Format analysis result into user-friendly summary"""
75
- available = analysis_result.get("data_availability", {}).get("available_reports", [])
76
- data_lake = analysis_result.get("data_lake_requirements", {}).get("reports_needed", [])
 
 
 
 
 
 
 
 
77
  unavailable = analysis_result.get("unavailable_data", [])
78
-
79
- interpretation = analysis_result.get("request_analysis", {}).get("interpretation", "")
80
-
81
  summary = [
82
  "### Data Request Summary",
83
  f"**Request Analysis**: \n{interpretation}\n",
84
  "\n**Data Availability**:\n"
85
  ]
86
-
87
  if available:
88
  summary.append("βœ… **Available in Web Data System**: ")
89
  for report in available:
90
- summary.append(f"- {report['name']}")
91
  summary.append(f"\nEstimated processing time: **3 working days**\n")
92
-
93
  if data_lake:
94
  summary.append("πŸ”„ **Requires Additional Database Query**: ")
95
  for report in data_lake:
96
- summary.append(f"- {report['report_type']}")
97
  summary.append(f"\nEstimated processing time: **2–4 weeks**\n")
98
-
99
  if unavailable:
100
  summary.append("❌ **Not Currently Available**: ")
101
  for item in unavailable:
102
- summary.append(f"- {item['report_type']}")
103
  summary.append("\nAction required: Schedule a meeting to discuss alternative data sources or solutions. We will follow up via email.\n")
104
-
 
105
  return "\n".join(summary)
 
106
 
107
  def process_request(name, employee_id, email, department, other_dept, request_details, frequency, urgency):
108
- """Process the data request and return both user and technical responses"""
109
  print("=== Debug: Received Inputs ===")
110
- print(f"Name: {name}")
111
- print(f"Employee ID: {employee_id}")
112
- print(f"Email: {email}")
113
- print(f"Department: {department}")
114
- print(f"Other Dept: {other_dept}")
115
- print(f"Request Details: {request_details}")
116
- print(f"Frequency: {frequency}")
117
- print(f"Urgency: {urgency}")
118
-
119
- # Validate inputs
120
  if not all([name, employee_id, email, request_details, department, frequency, urgency]):
121
- print("Validation failed - missing required fields")
122
  return "Please fill in all required fields.", None
123
-
124
- # Combine department info
125
  final_department = other_dept if department == "Other" else department
126
- print(f"Final department: {final_department}")
127
-
128
  try:
129
  # Analyze request
130
  print("Calling GPT service...")
131
  result = service.assess_request(request_details)
132
  print(f"GPT response received: {result}")
133
-
134
- # Create user-friendly summary
135
  user_summary = format_user_summary(result)
136
-
137
- # Prepare data for Google Sheets logging
 
138
  sheet_data = {
139
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
140
  "name": name,
@@ -148,12 +147,10 @@ def process_request(name, employee_id, email, department, other_dept, request_de
148
  "system_analysis": json.dumps(result, ensure_ascii=False)
149
  }
150
  sheets_logger.log_request(sheet_data)
151
-
152
  return user_summary, result
153
  except Exception as e:
154
- error_msg = f"Error processing request: {str(e)}"
155
- print(error_msg)
156
- return error_msg, None
157
 
158
  # Create Gradio interface
159
  with gr.Blocks() as demo:
 
72
  # Function to format user-friendly summaries
73
  def format_user_summary(analysis_result):
74
  """Format analysis result into user-friendly summary"""
75
+ available = [
76
+ report['report_type']
77
+ for report in analysis_result.get("required_reports", [])
78
+ if report['category'] == "OPD" # Example: assuming OPD reports are in Web Data System
79
+ ]
80
+ data_lake = [
81
+ report['report_type']
82
+ for report in analysis_result.get("required_reports", [])
83
+ if report['category'] != "OPD" # Example: assuming other categories require Data Lake queries
84
+ ]
85
  unavailable = analysis_result.get("unavailable_data", [])
86
+
87
+ interpretation = analysis_result.get("interpretation", "No interpretation available.")
88
+
89
  summary = [
90
  "### Data Request Summary",
91
  f"**Request Analysis**: \n{interpretation}\n",
92
  "\n**Data Availability**:\n"
93
  ]
94
+
95
  if available:
96
  summary.append("βœ… **Available in Web Data System**: ")
97
  for report in available:
98
+ summary.append(f"- {report}")
99
  summary.append(f"\nEstimated processing time: **3 working days**\n")
100
+
101
  if data_lake:
102
  summary.append("πŸ”„ **Requires Additional Database Query**: ")
103
  for report in data_lake:
104
+ summary.append(f"- {report}")
105
  summary.append(f"\nEstimated processing time: **2–4 weeks**\n")
106
+
107
  if unavailable:
108
  summary.append("❌ **Not Currently Available**: ")
109
  for item in unavailable:
110
+ summary.append(f"- {item}")
111
  summary.append("\nAction required: Schedule a meeting to discuss alternative data sources or solutions. We will follow up via email.\n")
112
+
113
+ # Return formatted summary
114
  return "\n".join(summary)
115
+
116
 
117
  def process_request(name, employee_id, email, department, other_dept, request_details, frequency, urgency):
 
118
  print("=== Debug: Received Inputs ===")
119
+ print(f"Name: {name}, Employee ID: {employee_id}, Email: {email}, Department: {department}, Request Details: {request_details}, Frequency: {frequency}, Urgency: {urgency}")
120
+
 
 
 
 
 
 
 
 
121
  if not all([name, employee_id, email, request_details, department, frequency, urgency]):
 
122
  return "Please fill in all required fields.", None
123
+
 
124
  final_department = other_dept if department == "Other" else department
125
+
 
126
  try:
127
  # Analyze request
128
  print("Calling GPT service...")
129
  result = service.assess_request(request_details)
130
  print(f"GPT response received: {result}")
131
+
132
+ # Format summary
133
  user_summary = format_user_summary(result)
134
+ print(f"User Summary: {user_summary}")
135
+
136
+ # Log request
137
  sheet_data = {
138
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
139
  "name": name,
 
147
  "system_analysis": json.dumps(result, ensure_ascii=False)
148
  }
149
  sheets_logger.log_request(sheet_data)
150
+
151
  return user_summary, result
152
  except Exception as e:
153
+ return f"Error processing request: {str(e)}", None
 
 
154
 
155
  # Create Gradio interface
156
  with gr.Blocks() as demo: