jeffrey1963 commited on
Commit
04755a3
·
verified ·
1 Parent(s): c013681

Upload NLP_dispatcher.py

Browse files
Files changed (1) hide show
  1. NLP_dispatcher.py +48 -0
NLP_dispatcher.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Define routing keywords for Extension Agents and Ag Lenders
4
+ extension_keywords = {
5
+ "Jerry": ["depreciation", "tractor", "equipment", "machinery"],
6
+ "Amanda": ["enterprise", "budget", "revenue", "expenses"],
7
+ "James": ["partial budget", "compare", "replace", "cost saving"],
8
+ "Edward": ["balance sheet", "assets", "liabilities", "net worth"],
9
+ "Alessandra": ["income statement", "profit", "loss", "cash flow"]
10
+ }
11
+
12
+ lender_keywords = {
13
+ "Carlos": ["loan", "financing", "refinance", "repayment"],
14
+ "Warren": ["approval", "final plan", "executive", "capstone"]
15
+ }
16
+
17
+ # Match farm plan to best agent or lender
18
+ def route_to_agent(farm_plan):
19
+ farm_plan_lower = farm_plan.lower()
20
+
21
+ for agent, keywords in extension_keywords.items():
22
+ for word in keywords:
23
+ if word in farm_plan_lower:
24
+ return f"📞 Connecting you to Extension Agent {agent}. They can help you with that topic and guide you through Extension resources."
25
+
26
+ for lender, keywords in lender_keywords.items():
27
+ for word in keywords:
28
+ if word in farm_plan_lower:
29
+ return f"🏦 Forwarding you to Loan Officer {lender} for project review and financial analysis."
30
+
31
+ return "🤖 Sorry, I couldn't match your plan to a specific agent or lender. Try using keywords like 'depreciation', 'income', or 'loan'."
32
+
33
+
34
+ with gr.Blocks() as app:
35
+ gr.Markdown("""
36
+ # 🧭 AgLendGPT Directory: Extension Agents & Lenders
37
+ Submit your farm plan below. We’ll connect you to the right Extension agent for support, or to an Ag Credit officer for projects.
38
+ """)
39
+
40
+ farm_plan_input = gr.Textbox(label="Describe your farm plan", placeholder="e.g., I want to expand with new equipment and need help calculating depreciation.", lines=4)
41
+ submit_btn = gr.Button("📡 Connect Me")
42
+ response = gr.Textbox(label="Routing Result")
43
+
44
+ submit_btn.click(fn=route_to_agent, inputs=farm_plan_input, outputs=response)
45
+
46
+
47
+ if __name__ == "__main__":
48
+ app.launch()