Spaces:
Sleeping
Sleeping
Commit
·
8b27fa0
1
Parent(s):
964980b
Added rest of the forms - Need to implement batch processing for them
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ with gr.Blocks() as demo:
|
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
-
with gr.Tab("
|
| 38 |
with gr.Row():
|
| 39 |
with gr.Column(scale=2):
|
| 40 |
img_input = gr.Image(
|
|
@@ -48,7 +48,8 @@ with gr.Blocks() as demo:
|
|
| 48 |
|
| 49 |
with gr.Column(scale=2):
|
| 50 |
# Dropdown for form names
|
| 51 |
-
gr.Markdown("##
|
|
|
|
| 52 |
|
| 53 |
# 2x2 grid for info fields
|
| 54 |
with gr.Row():
|
|
@@ -61,9 +62,11 @@ with gr.Blocks() as demo:
|
|
| 61 |
preview_output = gr.File(label="Download Filled Form")
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
| 64 |
upload_btn.click(
|
| 65 |
fn=extract_child_fee_info,
|
| 66 |
-
inputs=[img_input, emp_name, emp_code, department],
|
| 67 |
outputs=preview_output
|
| 68 |
)
|
| 69 |
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
+
with gr.Tab("Reimbursement Forms"):
|
| 38 |
with gr.Row():
|
| 39 |
with gr.Column(scale=2):
|
| 40 |
img_input = gr.Image(
|
|
|
|
| 48 |
|
| 49 |
with gr.Column(scale=2):
|
| 50 |
# Dropdown for form names
|
| 51 |
+
gr.Markdown("## Reimbursement Forms")
|
| 52 |
+
form_name = gr.Dropdown(choices=["Child Fee Reimbursement Form", "Internet Charges Form", "Mobile Reimbursement Form"], interactive=True, multiselect=False)
|
| 53 |
|
| 54 |
# 2x2 grid for info fields
|
| 55 |
with gr.Row():
|
|
|
|
| 62 |
preview_output = gr.File(label="Download Filled Form")
|
| 63 |
|
| 64 |
|
| 65 |
+
|
| 66 |
+
|
| 67 |
upload_btn.click(
|
| 68 |
fn=extract_child_fee_info,
|
| 69 |
+
inputs=[img_input, emp_name, emp_code, department,form_name],
|
| 70 |
outputs=preview_output
|
| 71 |
)
|
| 72 |
|
pipeline.py
CHANGED
|
@@ -43,7 +43,7 @@ reciept_system_prompt = (
|
|
| 43 |
|
| 44 |
fee_bill_system_prompt = (
|
| 45 |
"You are an expert at extracting data from fee bills. "
|
| 46 |
-
"Read the provided image of a
|
| 47 |
"from typing import List, Optional\n"
|
| 48 |
"class FeeItem(BaseModel):\n"
|
| 49 |
" bill_date: Optional[str] = None # Bill Date Field, leave null if not found\n"
|
|
@@ -145,7 +145,7 @@ def extract_info(pil_img):
|
|
| 145 |
return f"```json\n{json.dumps({'error': str(e), 'raw_output': raw_output}, indent=2)}\n```"
|
| 146 |
|
| 147 |
|
| 148 |
-
def extract_child_fee_info(img_input, emp_name, emp_code, department):
|
| 149 |
print(emp_name, emp_code, department)
|
| 150 |
processed_image = preprocess_image(img_input)
|
| 151 |
img_bytes = pil_to_bytes(processed_image)
|
|
@@ -178,12 +178,25 @@ def extract_child_fee_info(img_input, emp_name, emp_code, department):
|
|
| 178 |
if items and "bill_month" in items[0]:
|
| 179 |
bill_month = items[0]["bill_month"]
|
| 180 |
|
|
|
|
| 181 |
os.makedirs("outputs", exist_ok=True)
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
|
| 185 |
filled_pdf_path = fill_child_fee_pdf(
|
| 186 |
-
template_pdf_path="
|
| 187 |
output_pdf_path=output_pdf_path,
|
| 188 |
emp_name=emp_name,
|
| 189 |
emp_code=emp_code,
|
|
@@ -281,12 +294,10 @@ def extract_medical_info(pil_img, emp_name, emp_code, department, designation, c
|
|
| 281 |
}});
|
| 282 |
</script>
|
| 283 |
</body>'''
|
| 284 |
-
# Ensure we are replacing the </body> tag correctly
|
| 285 |
if "</body>" in html_content:
|
| 286 |
html_content = html_content.replace("</body>", script_to_inject, 1)
|
| 287 |
else:
|
| 288 |
-
|
| 289 |
-
html_content += script_to_inject.replace("</body>","") # remove the body tag we added if appending
|
| 290 |
|
| 291 |
|
| 292 |
output_dir = "outputs"
|
|
|
|
| 43 |
|
| 44 |
fee_bill_system_prompt = (
|
| 45 |
"You are an expert at extracting data from fee bills. "
|
| 46 |
+
"Read the provided image of a fee bill and return a JSON object that matches the following Pydantic model:\n"
|
| 47 |
"from typing import List, Optional\n"
|
| 48 |
"class FeeItem(BaseModel):\n"
|
| 49 |
" bill_date: Optional[str] = None # Bill Date Field, leave null if not found\n"
|
|
|
|
| 145 |
return f"```json\n{json.dumps({'error': str(e), 'raw_output': raw_output}, indent=2)}\n```"
|
| 146 |
|
| 147 |
|
| 148 |
+
def extract_child_fee_info(img_input, emp_name, emp_code, department, form_name):
|
| 149 |
print(emp_name, emp_code, department)
|
| 150 |
processed_image = preprocess_image(img_input)
|
| 151 |
img_bytes = pil_to_bytes(processed_image)
|
|
|
|
| 178 |
if items and "bill_month" in items[0]:
|
| 179 |
bill_month = items[0]["bill_month"]
|
| 180 |
|
| 181 |
+
|
| 182 |
os.makedirs("outputs", exist_ok=True)
|
| 183 |
+
|
| 184 |
+
if form_name == "Child Fee Reimbursement Form":
|
| 185 |
+
|
| 186 |
+
output_pdf_path = f"outputs/filled_child_fee_reimbursement_form_{uuid.uuid4().hex}.pdf"
|
| 187 |
+
|
| 188 |
+
elif form_name == "Internet Charges Form":
|
| 189 |
+
|
| 190 |
+
output_pdf_path = f"outputs/filled_internet_charges_reimbursement_form_{uuid.uuid4().hex}.pdf"
|
| 191 |
+
|
| 192 |
+
elif form_name == "Mobile Reimbursement Form":
|
| 193 |
+
|
| 194 |
+
output_pdf_path = f"outputs/filled_mobile_reimbursement_form_{uuid.uuid4().hex}.pdf"
|
| 195 |
+
|
| 196 |
|
| 197 |
|
| 198 |
filled_pdf_path = fill_child_fee_pdf(
|
| 199 |
+
template_pdf_path="templates/REIMBURSEMENT FORM.pdf",
|
| 200 |
output_pdf_path=output_pdf_path,
|
| 201 |
emp_name=emp_name,
|
| 202 |
emp_code=emp_code,
|
|
|
|
| 294 |
}});
|
| 295 |
</script>
|
| 296 |
</body>'''
|
|
|
|
| 297 |
if "</body>" in html_content:
|
| 298 |
html_content = html_content.replace("</body>", script_to_inject, 1)
|
| 299 |
else:
|
| 300 |
+
html_content += script_to_inject.replace("</body>","")
|
|
|
|
| 301 |
|
| 302 |
|
| 303 |
output_dir = "outputs"
|
templates/NetSol_logo.svg.png
ADDED
|
templates/{CHILD FEE REIMBURSEMENT FORM.pdf → REIMBURSEMENT FORM.pdf}
RENAMED
|
File without changes
|
templates/medical_form.html
CHANGED
|
@@ -24,8 +24,8 @@
|
|
| 24 |
.logo-placeholder {
|
| 25 |
width: 90px;
|
| 26 |
height: 90px;
|
| 27 |
-
background:
|
| 28 |
-
border: 1px solid
|
| 29 |
margin-right: 18px;
|
| 30 |
}
|
| 31 |
.header-title {
|
|
@@ -162,7 +162,7 @@
|
|
| 162 |
<div class="form-container">
|
| 163 |
<div class="form-header">
|
| 164 |
<div class="logo-placeholder">
|
| 165 |
-
|
| 166 |
</div>
|
| 167 |
<div class="header-title">
|
| 168 |
<h2>Medical Reimbursement Form</h2>
|
|
@@ -225,7 +225,7 @@
|
|
| 225 |
<table style="margin-top: 0;">
|
| 226 |
<tr class="total-row">
|
| 227 |
<td colspan="4" style="border: none;"></td>
|
| 228 |
-
<td style="border-top: none; border-left:
|
| 229 |
<input style="width: 80px; border: none; border-bottom: 1px solid #000; font-size: 16px; background: none; text-align: center;" type="number" step="0.01" min="0" name="total" readonly id="total_amount">
|
| 230 |
</td>
|
| 231 |
</tr>
|
|
|
|
| 24 |
.logo-placeholder {
|
| 25 |
width: 90px;
|
| 26 |
height: 90px;
|
| 27 |
+
background: white;
|
| 28 |
+
border: 1px solid white;
|
| 29 |
margin-right: 18px;
|
| 30 |
}
|
| 31 |
.header-title {
|
|
|
|
| 162 |
<div class="form-container">
|
| 163 |
<div class="form-header">
|
| 164 |
<div class="logo-placeholder">
|
| 165 |
+
<img src="NetSol_logo.svg.png" alt="NetSol Logo" style="width: 100%; height: 100%; object-fit: contain;">
|
| 166 |
</div>
|
| 167 |
<div class="header-title">
|
| 168 |
<h2>Medical Reimbursement Form</h2>
|
|
|
|
| 225 |
<table style="margin-top: 0;">
|
| 226 |
<tr class="total-row">
|
| 227 |
<td colspan="4" style="border: none;"></td>
|
| 228 |
+
<td style="border-top: none; border-left: 0px solid #000;">Total -
|
| 229 |
<input style="width: 80px; border: none; border-bottom: 1px solid #000; font-size: 16px; background: none; text-align: center;" type="number" step="0.01" min="0" name="total" readonly id="total_amount">
|
| 230 |
</td>
|
| 231 |
</tr>
|