Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
@@ -19,23 +21,170 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
@tool
|
22 |
-
def
|
23 |
-
"""
|
|
|
24 |
Args:
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
try:
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
except Exception as e:
|
34 |
-
return f"Error
|
|
|
|
|
|
|
|
|
|
|
35 |
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
final_answer = FinalAnswerTool()
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from typing import Dict, Optional
|
8 |
+
import json
|
9 |
|
10 |
from Gradio_UI import GradioUI
|
11 |
|
|
|
21 |
return "What magic will you build ?"
|
22 |
|
23 |
@tool
|
24 |
+
def get_payroll_laws(country: str, specific_area: Optional[str] = None) -> str:
|
25 |
+
"""Retrieves payroll laws and regulations from the specified country's tax office portal
|
26 |
+
|
27 |
Args:
|
28 |
+
country: The country name or ISO code (e.g., 'USA', 'United Kingdom', 'Germany')
|
29 |
+
specific_area: Optional specific area of payroll law (e.g., 'tax_rates', 'social_security', 'minimum_wage', 'overtime')
|
30 |
+
|
31 |
+
Returns:
|
32 |
+
A formatted string containing payroll law information for the specified country
|
33 |
"""
|
34 |
+
|
35 |
+
# Mapping of countries to their tax office portals (for reference)
|
36 |
+
tax_portals = {
|
37 |
+
'USA': 'https://www.irs.gov',
|
38 |
+
'UK': 'https://www.gov.uk/government/organisations/hm-revenue-customs',
|
39 |
+
'Germany': 'https://www.bzst.de',
|
40 |
+
'France': 'https://www.impots.gouv.fr',
|
41 |
+
'Canada': 'https://www.canada.ca/en/revenue-agency',
|
42 |
+
'Australia': 'https://www.ato.gov.au',
|
43 |
+
'India': 'https://www.incometax.gov.in',
|
44 |
+
'Japan': 'https://www.nta.go.jp',
|
45 |
+
'Singapore': 'https://www.iras.gov.sg',
|
46 |
+
'Netherlands': 'https://www.belastingdienst.nl'
|
47 |
+
}
|
48 |
+
|
49 |
+
# Normalize country input
|
50 |
+
country = country.upper().strip()
|
51 |
+
|
52 |
+
# Since we cannot directly scrape government websites without proper authorization,
|
53 |
+
# this is a demonstration structure that would return general payroll law information
|
54 |
+
# In production, you would integrate with official APIs or authorized data sources
|
55 |
+
|
56 |
try:
|
57 |
+
# Example structure of payroll laws data
|
58 |
+
# In production, this would fetch from actual APIs or databases
|
59 |
+
payroll_info = {
|
60 |
+
'USA': {
|
61 |
+
'tax_rates': {
|
62 |
+
'federal_income_tax': 'Progressive rates: 10%, 12%, 22%, 24%, 32%, 35%, 37%',
|
63 |
+
'social_security': '6.2% (employee), 6.2% (employer) on wages up to $160,200 (2023)',
|
64 |
+
'medicare': '1.45% (employee), 1.45% (employer), additional 0.9% for high earners'
|
65 |
+
},
|
66 |
+
'minimum_wage': 'Federal: $7.25/hour (varies by state)',
|
67 |
+
'overtime': 'Time and a half for hours over 40 per week (FLSA)',
|
68 |
+
'payroll_frequency': 'Varies: weekly, bi-weekly, semi-monthly, or monthly',
|
69 |
+
'withholding_requirements': 'Form W-4 for federal withholding',
|
70 |
+
'reporting': 'Quarterly Form 941, Annual Forms W-2 and W-3',
|
71 |
+
'portal': tax_portals.get('USA', 'N/A')
|
72 |
+
},
|
73 |
+
'UK': {
|
74 |
+
'tax_rates': {
|
75 |
+
'income_tax': 'Personal allowance: £12,570, Basic rate: 20%, Higher rate: 40%, Additional rate: 45%',
|
76 |
+
'national_insurance': 'Class 1: 12% on £12,570-£50,270, 2% above',
|
77 |
+
'employer_ni': '13.8% on earnings above £175/week'
|
78 |
+
},
|
79 |
+
'minimum_wage': 'National Living Wage: £10.42/hour (23+), varies by age',
|
80 |
+
'pension': 'Auto-enrollment minimum: 8% (3% employer, 5% employee)',
|
81 |
+
'payroll_frequency': 'Weekly or monthly',
|
82 |
+
'paye_system': 'Real Time Information (RTI) reporting required',
|
83 |
+
'reporting': 'Full Payment Submission (FPS) with each payroll',
|
84 |
+
'portal': tax_portals.get('UK', 'N/A')
|
85 |
+
},
|
86 |
+
'GERMANY': {
|
87 |
+
'tax_rates': {
|
88 |
+
'income_tax': 'Progressive: 0-45% based on income brackets',
|
89 |
+
'solidarity_surcharge': '5.5% of income tax (for high earners)',
|
90 |
+
'church_tax': '8-9% of income tax (if applicable)'
|
91 |
+
},
|
92 |
+
'social_insurance': {
|
93 |
+
'pension': '18.6% (9.3% each)',
|
94 |
+
'health': '14.6% + additional (split equally)',
|
95 |
+
'unemployment': '2.4% (1.2% each)',
|
96 |
+
'long_term_care': '3.05% (varies by state and children)'
|
97 |
+
},
|
98 |
+
'minimum_wage': '€12/hour (as of 2023)',
|
99 |
+
'payroll_frequency': 'Monthly standard',
|
100 |
+
'reporting': 'DEÜV electronic reporting system',
|
101 |
+
'portal': tax_portals.get('Germany', 'N/A')
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
# Check if country data is available
|
106 |
+
if country not in payroll_info:
|
107 |
+
# For countries not in our example data, provide a template response
|
108 |
+
return f"""Payroll Laws for {country}:
|
109 |
+
|
110 |
+
Unfortunately, detailed payroll law information for {country} is not currently available in this system.
|
111 |
+
|
112 |
+
To obtain accurate payroll laws for {country}, please:
|
113 |
+
1. Visit the official tax authority website: {tax_portals.get(country, 'Please search for the official tax office portal')}
|
114 |
+
2. Consult with a local payroll specialist or tax advisor
|
115 |
+
3. Check international payroll service providers for country-specific guides
|
116 |
+
|
117 |
+
Key areas to research:
|
118 |
+
- Income tax rates and brackets
|
119 |
+
- Social security contributions
|
120 |
+
- Mandatory benefits and insurance
|
121 |
+
- Minimum wage requirements
|
122 |
+
- Overtime regulations
|
123 |
+
- Payroll reporting requirements
|
124 |
+
- Payment frequency regulations
|
125 |
+
|
126 |
+
Note: Payroll laws change frequently. Always verify current regulations with official sources."""
|
127 |
+
|
128 |
+
# Get country data
|
129 |
+
country_data = payroll_info[country]
|
130 |
+
|
131 |
+
# Build response based on specific area or all information
|
132 |
+
if specific_area:
|
133 |
+
if specific_area in country_data:
|
134 |
+
info = country_data[specific_area]
|
135 |
+
return f"""Payroll Laws for {country} - {specific_area.replace('_', ' ').title()}:
|
136 |
+
|
137 |
+
{json.dumps(info, indent=2) if isinstance(info, dict) else info}
|
138 |
+
|
139 |
+
Source Portal: {country_data.get('portal', 'N/A')}
|
140 |
+
|
141 |
+
Note: This information is for reference only. Please verify with official sources for the most current regulations."""
|
142 |
+
else:
|
143 |
+
return f"Specific area '{specific_area}' not found. Available areas: {', '.join(country_data.keys())}"
|
144 |
+
|
145 |
+
# Return all payroll information
|
146 |
+
result = f"""Comprehensive Payroll Laws for {country}:
|
147 |
+
|
148 |
+
{'='*50}"""
|
149 |
+
|
150 |
+
for category, details in country_data.items():
|
151 |
+
if category != 'portal':
|
152 |
+
result += f"\n\n{category.replace('_', ' ').upper()}:"
|
153 |
+
if isinstance(details, dict):
|
154 |
+
for key, value in details.items():
|
155 |
+
result += f"\n • {key.replace('_', ' ').title()}: {value}"
|
156 |
+
else:
|
157 |
+
result += f"\n {details}"
|
158 |
+
|
159 |
+
result += f"\n\n{'='*50}"
|
160 |
+
result += f"\nOfficial Portal: {country_data.get('portal', 'N/A')}"
|
161 |
+
result += "\n\n⚠️ IMPORTANT: This information is for reference purposes only. Payroll laws change frequently."
|
162 |
+
result += "\nAlways consult official government sources or qualified professionals for current regulations."
|
163 |
+
|
164 |
+
return result
|
165 |
+
|
166 |
except Exception as e:
|
167 |
+
return f"""Error retrieving payroll laws for {country}: {str(e)}
|
168 |
+
|
169 |
+
Please try:
|
170 |
+
1. Checking the country name/code is correct
|
171 |
+
2. Specifying a valid area: 'tax_rates', 'social_security', 'minimum_wage', 'overtime'
|
172 |
+
3. Consulting the official tax portal directly
|
173 |
|
174 |
+
For production use, this tool would need:
|
175 |
+
- API integration with official government data sources
|
176 |
+
- Regular updates to reflect law changes
|
177 |
+
- Proper authentication and compliance with data usage policies"""
|
178 |
|
|
|
179 |
|
180 |
+
# Example usage with your HuggingFace model setup
|
181 |
+
if __name__ == "__main__":
|
182 |
+
# Test the tool
|
183 |
+
print(get_payroll_laws("USA"))
|
184 |
+
print("\n" + "="*70 + "\n")
|
185 |
+
print(get_payroll_laws("UK", "tax_rates"))
|
186 |
+
print("\n" + "="*70 + "\n")
|
187 |
+
print(get_payroll_laws("Germany", "social_insurance"))
|
188 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
189 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
190 |
|