Spaces:
Sleeping
Sleeping
Commit ·
3df8d41
1
Parent(s): d134cf4
app
Browse files
app.py
CHANGED
|
@@ -3,24 +3,53 @@ from transformers import pipeline
|
|
| 3 |
import re
|
| 4 |
|
| 5 |
# Load text classification pipeline
|
| 6 |
-
classifier = pipeline(
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
def process_application(company, monthly_revenue, monthly_expenses, requested_advance):
|
| 9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
application_text = f"""
|
| 11 |
-
Company: {company}
|
| 12 |
-
Monthly Revenue: ${monthly_revenue:,}
|
| 13 |
-
Monthly Expenses: ${monthly_expenses:,}
|
| 14 |
-
Requested Advance: ${requested_advance:,}
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Process with classifier
|
| 18 |
result = classifier(application_text)
|
| 19 |
label = result[0]['label']
|
| 20 |
score = result[0]['score']
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
decision = "Approve"
|
| 25 |
else:
|
| 26 |
decision = "Reject"
|
|
@@ -31,7 +60,11 @@ Requested Advance: ${requested_advance:,}
|
|
| 31 |
"requested_advance": requested_advance,
|
| 32 |
"risk_label": label,
|
| 33 |
"risk_score": score,
|
| 34 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
return str(output)
|
|
@@ -39,23 +72,24 @@ Requested Advance: ${requested_advance:,}
|
|
| 39 |
# Create Gradio interface
|
| 40 |
with gr.Blocks(title="MCA Application Processor") as demo:
|
| 41 |
gr.Markdown("# 💼 MCA Application Processor")
|
| 42 |
-
gr.Markdown("Enter application details to get risk assessment and decision.")
|
| 43 |
|
| 44 |
with gr.Row():
|
| 45 |
with gr.Column():
|
| 46 |
company = gr.Textbox(label="Company Name", value="Acme Corp")
|
| 47 |
-
monthly_revenue = gr.Number(label="Monthly Revenue ($)", value=120000)
|
| 48 |
-
monthly_expenses = gr.Number(label="Monthly Expenses ($)", value=90000)
|
| 49 |
-
requested_advance = gr.Number(label="Requested Advance ($)", value=50000)
|
|
|
|
| 50 |
|
| 51 |
submit_btn = gr.Button("Process Application", variant="primary")
|
| 52 |
|
| 53 |
with gr.Column():
|
| 54 |
-
output = gr.Textbox(label="Result", lines=10)
|
| 55 |
|
| 56 |
submit_btn.click(
|
| 57 |
fn=process_application,
|
| 58 |
-
inputs=[company, monthly_revenue, monthly_expenses, requested_advance],
|
| 59 |
outputs=output
|
| 60 |
)
|
| 61 |
|
|
|
|
| 3 |
import re
|
| 4 |
|
| 5 |
# Load text classification pipeline
|
| 6 |
+
classifier = pipeline(
|
| 7 |
+
"text-classification",
|
| 8 |
+
model="distilbert-base-uncased-finetuned-sst-2-english"
|
| 9 |
+
)
|
| 10 |
|
| 11 |
+
def process_application(company, monthly_revenue, monthly_expenses, requested_advance, additional_text):
|
| 12 |
+
# Calculate net income
|
| 13 |
+
net_income = monthly_revenue - monthly_expenses
|
| 14 |
+
|
| 15 |
+
# Define reasonable request rule for MCA
|
| 16 |
+
# Reasonable if advance <= 50% of net income and <= 80% of revenue
|
| 17 |
+
is_reasonable = (
|
| 18 |
+
(requested_advance <= (net_income * 0.5) if net_income > 0 else False)
|
| 19 |
+
and (requested_advance <= (monthly_revenue * 0.8))
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
reasonable_text = (
|
| 23 |
+
"\nNote: This request is considered reasonable for MCA based on net income and revenue guidelines."
|
| 24 |
+
if is_reasonable
|
| 25 |
+
else "\nNote: This request exceeds MCA reasonableness guidelines (advance > 50% of net income or > 80% of revenue)."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Create application text with qualitative descriptors and reasonable note
|
| 29 |
application_text = f"""
|
| 30 |
+
Company: {company}
|
| 31 |
+
Monthly Revenue: ${monthly_revenue:,}
|
| 32 |
+
Monthly Expenses: ${monthly_expenses:,}
|
| 33 |
+
Requested Advance: ${requested_advance:,}
|
| 34 |
+
{reasonable_text}
|
| 35 |
+
Additional Context: {additional_text or 'No additional context provided.'}
|
| 36 |
+
"""
|
| 37 |
|
| 38 |
# Process with classifier
|
| 39 |
result = classifier(application_text)
|
| 40 |
label = result[0]['label']
|
| 41 |
score = result[0]['score']
|
| 42 |
|
| 43 |
+
# Rule-based financial checks
|
| 44 |
+
ratio = monthly_revenue / monthly_expenses if monthly_expenses > 0 else float('inf')
|
| 45 |
+
advance_coverage = net_income / requested_advance if requested_advance > 0 else float('inf')
|
| 46 |
+
|
| 47 |
+
# Decision logic: Combine sentiment with financial rules
|
| 48 |
+
if (label == "POSITIVE" and
|
| 49 |
+
score > 0.9 and
|
| 50 |
+
ratio > 1.2 and
|
| 51 |
+
advance_coverage > 1.0 and
|
| 52 |
+
is_reasonable):
|
| 53 |
decision = "Approve"
|
| 54 |
else:
|
| 55 |
decision = "Reject"
|
|
|
|
| 60 |
"requested_advance": requested_advance,
|
| 61 |
"risk_label": label,
|
| 62 |
"risk_score": score,
|
| 63 |
+
"revenue_expense_ratio": round(ratio, 2),
|
| 64 |
+
"advance_coverage": round(advance_coverage, 2),
|
| 65 |
+
"reasonable_request": is_reasonable,
|
| 66 |
+
"decision": decision,
|
| 67 |
+
"additional_context": additional_text or "None"
|
| 68 |
}
|
| 69 |
|
| 70 |
return str(output)
|
|
|
|
| 72 |
# Create Gradio interface
|
| 73 |
with gr.Blocks(title="MCA Application Processor") as demo:
|
| 74 |
gr.Markdown("# 💼 MCA Application Processor")
|
| 75 |
+
gr.Markdown("Enter application details to get a risk assessment and decision. Decision is based on sentiment analysis, financial ratios (Revenue/Expenses > 1.2, Advance Coverage > 1.0), and a reasonable request rule (Advance <= 50% of net income and <= 80% of revenue).")
|
| 76 |
|
| 77 |
with gr.Row():
|
| 78 |
with gr.Column():
|
| 79 |
company = gr.Textbox(label="Company Name", value="Acme Corp")
|
| 80 |
+
monthly_revenue = gr.Number(label="Monthly Revenue ($)", value=120000, precision=0)
|
| 81 |
+
monthly_expenses = gr.Number(label="Monthly Expenses ($)", value=90000, precision=0)
|
| 82 |
+
requested_advance = gr.Number(label="Requested Advance ($)", value=50000, precision=0)
|
| 83 |
+
additional_text = gr.Textbox(label="Additional Context (Optional)", placeholder="e.g., 'Business has steady growth'", lines=2)
|
| 84 |
|
| 85 |
submit_btn = gr.Button("Process Application", variant="primary")
|
| 86 |
|
| 87 |
with gr.Column():
|
| 88 |
+
output = gr.Textbox(label="Result", lines=10, interactive=False)
|
| 89 |
|
| 90 |
submit_btn.click(
|
| 91 |
fn=process_application,
|
| 92 |
+
inputs=[company, monthly_revenue, monthly_expenses, requested_advance, additional_text],
|
| 93 |
outputs=output
|
| 94 |
)
|
| 95 |
|