Spaces:
Sleeping
Sleeping
jonathanjordan21
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -198,22 +198,39 @@ def get_calculation(request_code, plate_number):
|
|
198 |
calc = detail_perhitungan.get(request_code)
|
199 |
vehicle = vehicle_tax_info.get(plate_number)
|
200 |
|
201 |
-
if vehicle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
return None, None, None
|
203 |
-
|
204 |
-
harga_jual = vehicle.get("harga_jual")
|
205 |
-
formula = calc.get("formula")
|
206 |
-
result = formula(harga_jual)
|
207 |
-
description = inspect.getsource(formula).split(":", 2)[-1].strip()
|
208 |
-
result_detail = request_code + " - " + calc.get("name")
|
209 |
-
|
210 |
-
# out = "=============================================="
|
211 |
-
# out += "\n\nWajib Pajak ingin melakukan proses berikut:\n"
|
212 |
-
# out = ""
|
213 |
-
|
214 |
-
return result, str(description), result_detail
|
215 |
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
def build_output(result, description, result_detail, plate_number):
|
218 |
return build_outputs([result], [description], [result_detail], plate_number)
|
219 |
|
@@ -221,19 +238,20 @@ def build_output(result, description, result_detail, plate_number):
|
|
221 |
def build_outputs(results, descriptions, result_details, plate_number):
|
222 |
vehicle = vehicle_tax_info.get(plate_number)
|
223 |
|
224 |
-
out = "
|
225 |
-
out = "
|
226 |
out += "\n".join([k + " : " + str(v) if k != "no_rangka" else k + " : " + censor_middle(v) for k,v in vehicle.items()])
|
227 |
# out += "\n----------------------------------------------"
|
228 |
|
229 |
-
out += f"\nWajib Pajak dengan NoPol {plate_number} ingin melakukan proses berikut:\n"
|
|
|
230 |
|
231 |
for i, (res,desc,detail) in enumerate(zip(results, descriptions, result_details)):
|
232 |
harga_jual = str(vehicle.get("harga_jual"))
|
233 |
out += f"{i+1}. {detail}\nRumus: {desc}\nDetail perhitungan: {desc.replace('harga_jual', harga_jual)} = {res}\n"
|
234 |
|
235 |
# out += "----------------------------\nEstimasi biaya: "
|
236 |
-
out += "\n\n
|
237 |
|
238 |
if len(results) > 1:
|
239 |
out += " + ".join([f"Rp{x}" for x in results])
|
@@ -304,8 +322,7 @@ def respond(
|
|
304 |
# formula = kode_mohon.get("formula")
|
305 |
# description = inspect.getsource(formula).split(":", 2)[-1].strip()
|
306 |
|
307 |
-
|
308 |
-
|
309 |
for plate in plates:
|
310 |
results, descriptions, result_details = [], [], []
|
311 |
for code in request_numbers_copy:
|
@@ -320,6 +337,14 @@ def respond(
|
|
320 |
|
321 |
if results:
|
322 |
out += "\n\n" + build_outputs(results, descriptions, result_details, plate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
|
324 |
return out
|
325 |
|
@@ -336,17 +361,25 @@ def respond(
|
|
336 |
request_code = codes[scores.argmax()]
|
337 |
# "{:.2f}".format(a)
|
338 |
|
339 |
-
out = "Request code number: " + request_code[:3] + "\nRequest detail: " + request_code[6:] + f"\nConfidence score: {round(scores[s_max].tolist(),3)}" + "\nPlate numbers: " + plate_numbers
|
340 |
|
|
|
341 |
for plate in plates:
|
342 |
results, descriptions, result_details = [], [], []
|
343 |
result, description, result_detail = get_calculation(request_code[:3], plate)
|
344 |
|
345 |
if result != None:
|
346 |
results.append(result)
|
|
|
|
|
347 |
descriptions.append(description)
|
348 |
result_details.append(result_detail)
|
349 |
-
out += "\n\n" +
|
|
|
|
|
|
|
|
|
|
|
350 |
|
351 |
return out
|
352 |
|
|
|
198 |
calc = detail_perhitungan.get(request_code)
|
199 |
vehicle = vehicle_tax_info.get(plate_number)
|
200 |
|
201 |
+
if vehicle != None and calc != None:
|
202 |
+
harga_jual = vehicle.get("harga_jual")
|
203 |
+
formula = calc.get("formula")
|
204 |
+
result = formula(harga_jual)
|
205 |
+
description = inspect.getsource(formula).split(":", 2)[-1].strip()
|
206 |
+
result_detail = request_code + " - " + calc.get("name")
|
207 |
+
return result, str(description), result_detail
|
208 |
+
|
209 |
+
elif vehicle == None:
|
210 |
+
formula = calc.get("formula")
|
211 |
+
description = inspect.getsource(formula).split(":", 2)[-1].strip()
|
212 |
+
result_detail = request_code + " - " + calc.get("name")
|
213 |
+
return None, str(description), result_detail
|
214 |
+
|
215 |
+
else:
|
216 |
return None, None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
|
219 |
+
def build_output_formula(descriptions, result_details):
|
220 |
+
out = "----------------------------------------------------\n\n"
|
221 |
+
out = "Daftar Kode Permohonan:\n"
|
222 |
+
for i, (res,desc,detail) in enumerate(zip(results, descriptions, result_details)):
|
223 |
+
harga_jual = str(vehicle.get("harga_jual"))
|
224 |
+
out += f"{i+1}. {detail}\nRumus: {desc}\n"
|
225 |
+
return out
|
226 |
+
|
227 |
+
|
228 |
+
def build_output_vehicle(vehicle):
|
229 |
+
out = "----------------------------------------------------\n\n"
|
230 |
+
out = "Nomor Polisi: " + plate_number + "\n"
|
231 |
+
out += "\n".join([k + " : " + str(v) if k != "no_rangka" else k + " : " + censor_middle(v) for k,v in vehicle.items()])
|
232 |
+
return out
|
233 |
+
|
234 |
def build_output(result, description, result_detail, plate_number):
|
235 |
return build_outputs([result], [description], [result_detail], plate_number)
|
236 |
|
|
|
238 |
def build_outputs(results, descriptions, result_details, plate_number):
|
239 |
vehicle = vehicle_tax_info.get(plate_number)
|
240 |
|
241 |
+
out = "----------------------------------------------------\n\n"
|
242 |
+
out = "Nomor Polisi: " + plate_number + "\n"
|
243 |
out += "\n".join([k + " : " + str(v) if k != "no_rangka" else k + " : " + censor_middle(v) for k,v in vehicle.items()])
|
244 |
# out += "\n----------------------------------------------"
|
245 |
|
246 |
+
# out += f"\nWajib Pajak dengan NoPol {plate_number} ingin melakukan proses berikut:\n"
|
247 |
+
out += "\n\nDaftar Kode Permohonan:\n"
|
248 |
|
249 |
for i, (res,desc,detail) in enumerate(zip(results, descriptions, result_details)):
|
250 |
harga_jual = str(vehicle.get("harga_jual"))
|
251 |
out += f"{i+1}. {detail}\nRumus: {desc}\nDetail perhitungan: {desc.replace('harga_jual', harga_jual)} = {res}\n"
|
252 |
|
253 |
# out += "----------------------------\nEstimasi biaya: "
|
254 |
+
out += "\n\n\nEstimasi Biaya:"
|
255 |
|
256 |
if len(results) > 1:
|
257 |
out += " + ".join([f"Rp{x}" for x in results])
|
|
|
322 |
# formula = kode_mohon.get("formula")
|
323 |
# description = inspect.getsource(formula).split(":", 2)[-1].strip()
|
324 |
|
325 |
+
out = ""
|
|
|
326 |
for plate in plates:
|
327 |
results, descriptions, result_details = [], [], []
|
328 |
for code in request_numbers_copy:
|
|
|
337 |
|
338 |
if results:
|
339 |
out += "\n\n" + build_outputs(results, descriptions, result_details, plate)
|
340 |
+
elif descriptions:
|
341 |
+
out += "\n\n" + build_output_formula(descriptions, result_details)
|
342 |
+
elif vehicle_tax_info.get(plate):
|
343 |
+
out += "\n\n" + build_output_vehicle(vehicle_tax_info.get(plate))
|
344 |
+
else:
|
345 |
+
# + request_details + f"\n\nConfidence score:\n{request_scores}"
|
346 |
+
out += "Request code number:\n" + request_numbers + "\n\nRequest detail:\n" + "\n\nPlate numbers: " + plate_numbers
|
347 |
+
|
348 |
|
349 |
return out
|
350 |
|
|
|
361 |
request_code = codes[scores.argmax()]
|
362 |
# "{:.2f}".format(a)
|
363 |
|
364 |
+
# out = "Request code number: " + request_code[:3] + "\nRequest detail: " + request_code[6:] + f"\nConfidence score: {round(scores[s_max].tolist(),3)}" + "\nPlate numbers: " + plate_numbers
|
365 |
|
366 |
+
out = ""
|
367 |
for plate in plates:
|
368 |
results, descriptions, result_details = [], [], []
|
369 |
result, description, result_detail = get_calculation(request_code[:3], plate)
|
370 |
|
371 |
if result != None:
|
372 |
results.append(result)
|
373 |
+
out += "\n\n" + build_outputs(results, descriptions, result_details, plate)
|
374 |
+
elif description != None:
|
375 |
descriptions.append(description)
|
376 |
result_details.append(result_detail)
|
377 |
+
out += "\n\n" + build_output_formula(descriptions, result_details)
|
378 |
+
elif vehicle_tax_info.get(plate):
|
379 |
+
out += "\n\n" + build_output_vehicle(vehicle_tax_info.get(plate))
|
380 |
+
else:
|
381 |
+
# + request_code[6:] + f"\nConfidence score: {round(scores[s_max].tolist(),3)}"
|
382 |
+
out += "Request code number: " + request_code[:3] + "\nRequest detail: " + "\nPlate numbers: " + plate_numbers
|
383 |
|
384 |
return out
|
385 |
|