SuriRaja commited on
Commit
897d857
·
verified ·
1 Parent(s): f2938a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +215 -0
app.py ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from datetime import datetime
4
+
5
+ # Load Excel file
6
+ file_path = 'data.xlsx'
7
+
8
+ truck_owners_df = pd.read_excel(file_path, sheet_name='Truck Owners')
9
+ transporters_df = pd.read_excel(file_path, sheet_name='Transporters')
10
+ customer_services_df = pd.read_excel(file_path, sheet_name='Customer Services')
11
+ admins_df = pd.read_excel(file_path, sheet_name='Admins')
12
+ transit_status_df = pd.read_excel(file_path, sheet_name='Transit Status')
13
+ users_df = pd.read_excel(file_path, sheet_name='Users')
14
+
15
+ def authenticate(username, password):
16
+ user = users_df[(users_df['Username'] == username) & (users_df['Password'] == password)]
17
+ if not user.empty:
18
+ return user.iloc[0]['Role']
19
+ return None
20
+
21
+ def display_data(persona):
22
+ if persona == "Truck Owner":
23
+ return truck_owners_df
24
+ elif persona == "Transporter":
25
+ return transporters_df
26
+ elif persona == "Customer Service":
27
+ return customer_services_df
28
+ elif persona == "Admin":
29
+ return admins_df
30
+ elif persona == "Transit Status":
31
+ return transit_status_df
32
+
33
+ def add_truck_owner(name, vehicle_id, vehicle_type, route, load_availability, source, destination):
34
+ global truck_owners_df
35
+ new_id = truck_owners_df['Truck Owner ID'].max() + 1
36
+ new_row = pd.DataFrame({
37
+ 'Truck Owner ID': [new_id],
38
+ 'Name': [name],
39
+ 'Vehicle ID': [vehicle_id],
40
+ 'Vehicle Type': [vehicle_type],
41
+ 'Subscription Status': ['Pending'],
42
+ 'KYC Status': ['Pending'],
43
+ 'Route': [route],
44
+ 'Load Availability': [load_availability],
45
+ 'Source': [source],
46
+ 'Destination': [destination],
47
+ 'Transit Status': ['Pending'],
48
+ 'GPS Tracking': ['Disabled']
49
+ })
50
+ truck_owners_df = pd.concat([truck_owners_df, new_row], ignore_index=True)
51
+ truck_owners_df.to_excel(file_path, sheet_name='Truck Owners', index=False)
52
+ return truck_owners_df
53
+
54
+ def add_transporter(company_name, load_requirements, source, destination):
55
+ global transporters_df
56
+ new_id = transporters_df['Transporter ID'].max() + 1
57
+ new_row = pd.DataFrame({
58
+ 'Transporter ID': [new_id],
59
+ 'Company Name': [company_name],
60
+ 'KYC Status': ['Pending'],
61
+ 'Load Requirements': [load_requirements],
62
+ 'Source': [source],
63
+ 'Destination': [destination],
64
+ 'Assigned Customer Service ID': [None],
65
+ 'Booking Status': ['Pending'],
66
+ 'Current Truck Location': [None]
67
+ })
68
+ transporters_df = pd.concat([transporters_df, new_row], ignore_index=True)
69
+ transporters_df.to_excel(file_path, sheet_name='Transporters', index=False)
70
+ return transporters_df
71
+
72
+ def update_transit_status(transit_id, current_location, status):
73
+ global transit_status_df
74
+ transit_status_df.loc[transit_status_df['Transit ID'] == transit_id, ['Current Location', 'Status']] = current_location, status
75
+ transit_status_df.to_excel(file_path, sheet_name='Transit Status', index=False)
76
+ return transit_status_df
77
+
78
+ def update_transporter_status(transporter_id, load_requirements):
79
+ global transporters_df
80
+ transporters_df.loc[transporters_df['Transporter ID'] == transporter_id, 'Load Requirements'] = load_requirements
81
+ transporters_df.to_excel(file_path, sheet_name='Transporters', index=False)
82
+ return transporters_df
83
+
84
+ def update_customer_service(service_rep_id, booking_status, delivery_status):
85
+ global customer_services_df
86
+ customer_services_df.loc[customer_services_df['Service Rep ID'] == service_rep_id, ['Booking Status', 'Delivery Status']] = booking_status, delivery_status
87
+ customer_services_df.to_excel(file_path, sheet_name='Customer Services', index=False)
88
+ return customer_services_df
89
+
90
+ def verify_kyc(admin_id, truck_owner_id):
91
+ global admins_df, truck_owners_df
92
+ if admins_df.loc[admins_df['Admin ID'] == admin_id, 'KYC Verification Status'].iloc[0] == 'Verified':
93
+ truck_owners_df.loc[truck_owners_df['Truck Owner ID'] == truck_owner_id, 'KYC Status'] = 'Verified'
94
+ truck_owners_df.to_excel(file_path, sheet_name='Truck Owners', index=False)
95
+ return truck_owners_df
96
+
97
+ def update_gps_location(transit_id, new_location):
98
+ global transit_status_df, transporters_df
99
+ transit_status_df.loc[transit_status_df['Transit ID'] == transit_id, 'Current Location'] = new_location
100
+ transporter_id = transit_status_df.loc[transit_status_df['Transit ID'] == transit_id, 'Transporter ID'].iloc[0]
101
+ transporters_df.loc[transporters_df['Transporter ID'] == transporter_id, 'Current Truck Location'] = new_location
102
+ transit_status_df.to_excel(file_path, sheet_name='Transit Status', index=False)
103
+ transporters_df.to_excel(file_path, sheet_name='Transporters', index=False)
104
+ return transit_status_df, transporters_df
105
+
106
+ def check_booking_status(transporter_id):
107
+ global transporters_df
108
+ booking_status = transporters_df.loc[transporters_df['Transporter ID'] == transporter_id, 'Booking Status'].iloc[0]
109
+ current_location = transporters_df.loc[transporters_df['Transporter ID'] == transporter_id, 'Current Truck Location'].iloc[0]
110
+ return f"Booking Status: {booking_status}, Current Location: {current_location}"
111
+
112
+ # Gradio interface
113
+ with gr.Blocks() as demo:
114
+ gr.Markdown("## Instacomm App Login")
115
+
116
+ username = gr.Textbox(label="Username")
117
+ password = gr.Textbox(label="Password", type="password")
118
+ login_btn = gr.Button("Login")
119
+ login_status = gr.Text()
120
+
121
+ def login(username, password):
122
+ role = authenticate(username, password)
123
+ if role:
124
+ if role == "Truck Owner":
125
+ return truck_owner_ui()
126
+ elif role == "Transporter":
127
+ return transporter_ui()
128
+ elif role == "Customer Service":
129
+ return customer_service_ui()
130
+ elif role == "Admin":
131
+ return admin_ui()
132
+ else:
133
+ return "Invalid credentials"
134
+
135
+ def truck_owner_ui():
136
+ with gr.Column():
137
+ gr.Markdown("### Truck Owner Functions")
138
+ name = gr.Textbox(label="Name")
139
+ vehicle_id = gr.Textbox(label="Vehicle ID")
140
+ vehicle_type = gr.Textbox(label="Vehicle Type")
141
+ route = gr.Textbox(label="Route")
142
+ load_availability = gr.Textbox(label="Load Availability")
143
+ source = gr.Textbox(label="Source")
144
+ destination = gr.Textbox(label="Destination")
145
+ add_btn = gr.Button("Add Truck Owner")
146
+ data_display = gr.DataFrame()
147
+ add_btn.click(add_truck_owner, inputs=[name, vehicle_id, vehicle_type, route, load_availability, source, destination], outputs=data_display)
148
+
149
+ gr.Markdown("### View Truck Owners Data")
150
+ view_data_btn = gr.Button("View Truck Owners Data")
151
+ view_data_btn.click(display_data, inputs="Truck Owner", outputs=data_display)
152
+
153
+ gr.Markdown("### Truck Owner Verification Status")
154
+ verified_status = gr.DataFrame(truck_owners_df[['Truck Owner ID', 'Name', 'KYC Status', 'Transit Status', 'Load Availability', 'Source', 'Destination']])
155
+
156
+ def transporter_ui():
157
+ with gr.Column():
158
+ gr.Markdown("### Transporter Functions")
159
+ company_name = gr.Textbox(label="Company Name")
160
+ load_requirements = gr.Textbox(label="Load Requirements")
161
+ source = gr.Textbox(label="Source")
162
+ destination = gr.Textbox(label="Destination")
163
+ add_btn = gr.Button("Add Transporter")
164
+ data_display = gr.DataFrame()
165
+ add_btn.click(add_transporter, inputs=[company_name, load_requirements, source, destination], outputs=data_display)
166
+
167
+ transporter_id = gr.Number(label="Transporter ID")
168
+ load_requirements_update = gr.Textbox(label="Load Requirements")
169
+ update_btn = gr.Button("Update Load Requirements")
170
+ updated_data = gr.DataFrame()
171
+ update_btn.click(update_transporter_status, inputs=[transporter_id, load_requirements_update], outputs=updated_data)
172
+
173
+ gr.Markdown("### View Transporters Data")
174
+ view_data_btn = gr.Button("View Transporters Data")
175
+ view_data_btn.click(display_data, inputs="Transporter", outputs=updated_data)
176
+
177
+ gr.Markdown("### Check Booking Status and Current Truck Location")
178
+ check_status_btn = gr.Button("Check Booking Status")
179
+ status_display = gr.Text()
180
+ check_status_btn.click(check_booking_status, inputs=transporter_id, outputs=status_display)
181
+
182
+ def customer_service_ui():
183
+ with gr.Column():
184
+ gr.Markdown("### Customer Service Functions")
185
+ service_rep_id = gr.Number(label="Service Rep ID")
186
+ booking_status = gr.Textbox(label="Booking Status")
187
+ delivery_status = gr.Textbox(label="Delivery Status")
188
+ update_btn = gr.Button("Update Booking and Delivery Status")
189
+ updated_data = gr.DataFrame()
190
+ update_btn.click(update_customer_service, inputs=[service_rep_id, booking_status, delivery_status], outputs=updated_data)
191
+
192
+ gr.Markdown("### View Customer Services Data")
193
+ view_data_btn = gr.Button("View Customer Services Data")
194
+ view_data_btn.click(display_data, inputs="Customer Service", outputs=updated_data)
195
+
196
+ gr.Markdown("### Truck Load and Availability")
197
+ load_status = gr.DataFrame(truck_owners_df[['Truck Owner ID', 'Name', 'Load Availability', 'Route', 'Transit Status', 'Source', 'Destination']])
198
+
199
+ def admin_ui():
200
+ with gr.Column():
201
+ gr.Markdown("### Admin Functions")
202
+ admin_id = gr.Number(label="Admin ID")
203
+ truck_owner_id = gr.Number(label="Truck Owner ID")
204
+ verify_btn = gr.Button("Verify KYC")
205
+ verified_data = gr.DataFrame()
206
+ verify_btn.click(verify_kyc, inputs=[admin_id, truck_owner_id], outputs=verified_data)
207
+
208
+ gr.Markdown("### View Admins Data")
209
+ view_data_btn = gr.Button("View Admins Data")
210
+ view_data_btn.click(display_data, inputs="Admin", outputs=verified_data)
211
+
212
+ login_btn.click(login, inputs=[username, password], outputs=login_status)
213
+
214
+ # Launch the app
215
+ demo.launch()