Spaces:
Sleeping
Sleeping
Update NLP_dispatcher.py
Browse files- 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 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 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 |
+
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()
|