dschandra commited on
Commit
1f6beaa
·
verified ·
1 Parent(s): c0dd2b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -25
app.py CHANGED
@@ -35,13 +35,6 @@ def clean_description(description, item_number=None):
35
 
36
  return description.strip()
37
 
38
- # Function to clean item description
39
- def clean_description(description):
40
- """
41
- Cleans up the description for an item to ensure it's correctly formatted.
42
- """
43
- return description.strip()
44
-
45
  # Function to extract PO items with better error handling and checks
46
  def parse_po_items_with_filters(text):
47
  """
@@ -67,7 +60,7 @@ def parse_po_items_with_filters(text):
67
  # Save the previous item if current_item is not None
68
  if current_item is not None:
69
  # Clean and add the description to the current item
70
- current_item["Description"] = clean_description(" ".join(description_accumulator).strip())
71
  data.append(current_item)
72
  description_accumulator = [] # Reset description accumulator
73
  print(f"Item {current_item['Item']} added to data.") # Debugging
@@ -107,7 +100,7 @@ def parse_po_items_with_filters(text):
107
  # Finalize the last item
108
  if current_item is not None:
109
  # Clean and add the description to the current item
110
- current_item["Description"] = clean_description(" ".join(description_accumulator).strip())
111
  data.append(current_item)
112
  print(f"Finalized Item {current_item['Item']}") # Debugging
113
 
@@ -144,22 +137,6 @@ def parse_po_items_with_filters(text):
144
  df = pd.DataFrame(data)
145
  return df, "Data extracted successfully."
146
 
147
- # Example text (as provided)
148
- text = """
149
- ITEM 1 Stainless Steel RATING AND DIAGRAM PLATE 24 Nos. 3.00 72.00
150
- As per Drg.No. G 000822 RI RDP 50KVA NT001 51 SIZE : 150mm X 160mm X 1.00mm Thick With Serial No:NT00151 97 to 121 Mfd:-2022
151
- ITEM 2 Stainless Steel RATING AND DIAGRAM PLATE 12 Nos. 3.80 45.60
152
- As per Drg.to.G 000816 R2 RDP 600KVA NT00152 SIZE : 150mm X 260mm X 1.00mm Thick With Serial No:NT00I53 38 to 50 Mfd:-2022
153
- """
154
-
155
- # Running the function
156
- df, status = parse_po_items_with_filters(text)
157
- print(status)
158
- if df is not None:
159
- print(df)
160
-
161
-
162
-
163
  # Function: Save to Excel
164
  def save_to_excel(df, output_path="extracted_po_data.xlsx"):
165
  """
 
35
 
36
  return description.strip()
37
 
 
 
 
 
 
 
 
38
  # Function to extract PO items with better error handling and checks
39
  def parse_po_items_with_filters(text):
40
  """
 
60
  # Save the previous item if current_item is not None
61
  if current_item is not None:
62
  # Clean and add the description to the current item
63
+ current_item["Description"] = clean_description(" ".join(description_accumulator).strip(), current_item["Item"])
64
  data.append(current_item)
65
  description_accumulator = [] # Reset description accumulator
66
  print(f"Item {current_item['Item']} added to data.") # Debugging
 
100
  # Finalize the last item
101
  if current_item is not None:
102
  # Clean and add the description to the current item
103
+ current_item["Description"] = clean_description(" ".join(description_accumulator).strip(), current_item["Item"])
104
  data.append(current_item)
105
  print(f"Finalized Item {current_item['Item']}") # Debugging
106
 
 
137
  df = pd.DataFrame(data)
138
  return df, "Data extracted successfully."
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  # Function: Save to Excel
141
  def save_to_excel(df, output_path="extracted_po_data.xlsx"):
142
  """