utkarsh134 commited on
Commit
bec3131
·
verified ·
1 Parent(s): 6eb672d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -9
main.py CHANGED
@@ -48,7 +48,7 @@ async def process_image(
48
  metal_data = processed_data["Metal Details"]
49
  diamonds = processed_data["Diamonds"]
50
 
51
- # Calculate initial diamond values
52
  diamond_values_sum = 0
53
  for idx, diamond in enumerate(diamonds):
54
  rate = float(diamond_rates_dict.get(str(idx), 0))
@@ -58,7 +58,7 @@ async def process_image(
58
  diamond["Diamond Value"] = diamond_value
59
  diamond_values_sum += diamond_value
60
 
61
- # Apply markup to finding values - before updating metal_data
62
  if finding_markup_type == "percentage":
63
  finding_markup_factor = 1 + (finding_markup_value / 100)
64
  finding_14kt = round(finding_14kt * finding_markup_factor, 2)
@@ -73,10 +73,10 @@ async def process_image(
73
  finding_18kt = round(finding_18kt * finding_markup_value, 2)
74
  finding_plt = round(finding_plt * finding_markup_value, 2)
75
 
76
- # Calculate labour based on accessory type
77
  metal_data = processor.calculate_labour(metal_data)
78
 
79
- # Update finding names based on accessory type
80
  finding_key_map = {
81
  "pendant": {
82
  "14kt": "Finding For Gold 14KT",
@@ -108,14 +108,14 @@ async def process_image(
108
  })
109
 
110
 
111
- # Calculate Gold Lock and Platinum Lock values
112
  metal_data.update({
113
  "Gold Lock": round(metal_data.get("Wt. in gram 14K", 0) * 0.15 +
114
  metal_data.get("Wt. in gram 18K", 0) * 0.15, 2),
115
  "Platinum Lock": round(metal_data.get("Wt. in gram PLT", 0) * 0.25, 2)
116
  })
117
 
118
- # Apply markup to gold values - only percentage or fixed
119
  if gold_markup_type == "percentage":
120
  gold_markup_factor = 1 + (gold_markup_value / 100)
121
  metal_data["Gold Value 14K"] = round(metal_data["Gold Value 14K"] * gold_markup_factor, 2)
@@ -231,7 +231,7 @@ async def process_image(
231
 
232
  findings_data = {}
233
  for col in columns_config["finding_columns"]:
234
- findings_data[col] = metal_data.get(col, 0) # Use 0 as default value
235
 
236
  findings_df = pd.DataFrame([findings_data])
237
 
@@ -265,13 +265,13 @@ async def process_image(
265
  ], axis=1)
266
 
267
  for col in columns_config["price_columns"]:
268
- if col in final_df.columns: # Check if column exists
269
  final_df[col] = final_df[col].astype(str)
270
  final_df[col] = final_df[col].apply(lambda x: x.strip('"').strip("'") if x else '')
271
  if "GBP" in col:
272
  final_df[col] = final_df[col].apply(lambda x: x.replace('£', '£') if x else '')
273
 
274
- # Add this before creating the final DataFrame
275
  print("Finding columns config:", columns_config["finding_columns"])
276
  print("Metal data finding keys:", [k for k in metal_data.keys() if "Finding" in k])
277
  print("Findings data:", findings_data)
 
48
  metal_data = processed_data["Metal Details"]
49
  diamonds = processed_data["Diamonds"]
50
 
51
+
52
  diamond_values_sum = 0
53
  for idx, diamond in enumerate(diamonds):
54
  rate = float(diamond_rates_dict.get(str(idx), 0))
 
58
  diamond["Diamond Value"] = diamond_value
59
  diamond_values_sum += diamond_value
60
 
61
+
62
  if finding_markup_type == "percentage":
63
  finding_markup_factor = 1 + (finding_markup_value / 100)
64
  finding_14kt = round(finding_14kt * finding_markup_factor, 2)
 
73
  finding_18kt = round(finding_18kt * finding_markup_value, 2)
74
  finding_plt = round(finding_plt * finding_markup_value, 2)
75
 
76
+
77
  metal_data = processor.calculate_labour(metal_data)
78
 
79
+
80
  finding_key_map = {
81
  "pendant": {
82
  "14kt": "Finding For Gold 14KT",
 
108
  })
109
 
110
 
111
+
112
  metal_data.update({
113
  "Gold Lock": round(metal_data.get("Wt. in gram 14K", 0) * 0.15 +
114
  metal_data.get("Wt. in gram 18K", 0) * 0.15, 2),
115
  "Platinum Lock": round(metal_data.get("Wt. in gram PLT", 0) * 0.25, 2)
116
  })
117
 
118
+
119
  if gold_markup_type == "percentage":
120
  gold_markup_factor = 1 + (gold_markup_value / 100)
121
  metal_data["Gold Value 14K"] = round(metal_data["Gold Value 14K"] * gold_markup_factor, 2)
 
231
 
232
  findings_data = {}
233
  for col in columns_config["finding_columns"]:
234
+ findings_data[col] = metal_data.get(col, 0)
235
 
236
  findings_df = pd.DataFrame([findings_data])
237
 
 
265
  ], axis=1)
266
 
267
  for col in columns_config["price_columns"]:
268
+ if col in final_df.columns:
269
  final_df[col] = final_df[col].astype(str)
270
  final_df[col] = final_df[col].apply(lambda x: x.strip('"').strip("'") if x else '')
271
  if "GBP" in col:
272
  final_df[col] = final_df[col].apply(lambda x: x.replace('£', '£') if x else '')
273
 
274
+
275
  print("Finding columns config:", columns_config["finding_columns"])
276
  print("Metal data finding keys:", [k for k in metal_data.keys() if "Finding" in k])
277
  print("Findings data:", findings_data)