jeffrey1963 commited on
Commit
08cfc67
·
verified ·
1 Parent(s): ef23b59

Update NLP_dispatcher.py

Browse files
Files changed (1) hide show
  1. NLP_dispatcher.py +58 -48
NLP_dispatcher.py CHANGED
@@ -1,48 +1,58 @@
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()
 
 
 
 
 
 
 
 
 
 
 
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
+ JERRY_URL = os.environ.get("JERRY_URL", "https://huggingface.co/spaces/jeffrey1963/Jerry_Depreciation")
18
+
19
+
20
+ # Match farm plan to best agent or lender
21
+ def route_to_agent(farm_plan):
22
+ farm_plan_lower = farm_plan.lower()
23
+
24
+ for agent, keywords in extension_keywords.items():
25
+ for word in keywords:
26
+ if word in farm_plan_lower:
27
+ return f"📞 Connecting you to Extension Agent {agent}. They can help you with that topic and guide you through Extension resources."
28
+
29
+ for lender, keywords in lender_keywords.items():
30
+ for word in keywords:
31
+ if word in farm_plan_lower:
32
+ return f"🏦 Forwarding you to Loan Officer {lender} for project review and financial analysis."
33
+
34
+ return "🤖 Sorry, I couldn't match your plan to a specific agent or lender. Try using keywords like 'depreciation', 'income', or 'loan'."
35
+
36
+ def render_result(route, student_id):
37
+ if route == "extension_jerry":
38
+ link = f"{JERRY_URL}?student_id={student_id or ''}"
39
+ return (f"☎️ Connecting you to **Extension Agent Jerry** for depreciation help.\n\n"
40
+ f"➡️ **Open Jerry**: {link}")
41
+ # ... other routes ...
42
+
43
+
44
+ with gr.Blocks() as app:
45
+ gr.Markdown("""
46
+ # 🧭 AgLendGPT Directory: Extension Agents & Lenders
47
+ Submit your farm plan below. We’ll connect you to the right Extension agent for support, or to an Ag Credit officer for projects.
48
+ """)
49
+
50
+ 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)
51
+ submit_btn = gr.Button("📡 Connect Me")
52
+ response = gr.Textbox(label="Routing Result")
53
+
54
+ submit_btn.click(fn=route_to_agent, inputs=farm_plan_input, outputs=response)
55
+
56
+
57
+ if __name__ == "__main__":
58
+ app.launch()