Spaces:
Runtime error
Runtime error
Changes UI of the app.
Browse files
app.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
#Gradio app
|
| 2 |
-
# app.py
|
| 3 |
# app.py - Optimized with better timeout handling
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
|
@@ -194,7 +192,6 @@ def test_service():
|
|
| 194 |
except Exception as e:
|
| 195 |
return f"β **Test Error**: {str(e)}"
|
| 196 |
|
| 197 |
-
# Create the interface with better UX
|
| 198 |
with gr.Blocks(
|
| 199 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
|
| 200 |
title="π Personal Finance Strategist",
|
|
@@ -207,105 +204,99 @@ with gr.Blocks(
|
|
| 207 |
border-radius: 8px;
|
| 208 |
margin: 10px 0;
|
| 209 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
"""
|
| 211 |
) as interface:
|
| 212 |
|
| 213 |
gr.Markdown(
|
| 214 |
"""
|
| 215 |
-
# π Personal Finance Strategist
|
| 216 |
**AI-Powered Investment Strategy Generator**
|
| 217 |
-
|
| 218 |
-
Get personalized investment recommendations based on your financial profile and goals.
|
| 219 |
-
|
| 220 |
-
---
|
| 221 |
"""
|
| 222 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
with gr.Row():
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
gr.Markdown("### π° Financial Information")
|
| 245 |
-
income = gr.Number(
|
| 246 |
-
label="Monthly Income ($)",
|
| 247 |
-
value=6000,
|
| 248 |
-
minimum=0,
|
| 249 |
-
info="Your total monthly income before taxes"
|
| 250 |
-
)
|
| 251 |
-
expenses = gr.Number(
|
| 252 |
-
label="Monthly Expenses ($)",
|
| 253 |
-
value=4000,
|
| 254 |
-
minimum=0,
|
| 255 |
-
info="Your total monthly expenses"
|
| 256 |
-
)
|
| 257 |
-
|
| 258 |
-
with gr.Column(scale=1):
|
| 259 |
-
gr.Markdown("### π― Investment Preferences")
|
| 260 |
-
risk_profile = gr.Radio(
|
| 261 |
-
choices=["Conservative", "Moderate", "Aggressive"],
|
| 262 |
-
label="Risk Tolerance",
|
| 263 |
-
value="Moderate",
|
| 264 |
-
info="How comfortable are you with investment risk?"
|
| 265 |
-
)
|
| 266 |
-
goal = gr.Textbox(
|
| 267 |
-
label="Financial Goal",
|
| 268 |
-
placeholder="e.g., buy a house, retirement, emergency fund, child's education",
|
| 269 |
-
info="What are you saving/investing for?"
|
| 270 |
-
)
|
| 271 |
-
timeframe = gr.Textbox(
|
| 272 |
-
label="Investment Timeframe",
|
| 273 |
-
placeholder="e.g., 5 years, 10 years, until retirement",
|
| 274 |
-
info="How long do you plan to invest?"
|
| 275 |
-
)
|
| 276 |
-
|
| 277 |
-
gr.Markdown("---")
|
| 278 |
-
|
| 279 |
-
with gr.Row():
|
| 280 |
-
submit_btn = gr.Button(
|
| 281 |
-
"π Generate Investment Strategy",
|
| 282 |
-
variant="primary",
|
| 283 |
-
size="lg"
|
| 284 |
-
)
|
| 285 |
-
test_btn = gr.Button(
|
| 286 |
-
"π Test Service",
|
| 287 |
-
variant="secondary",
|
| 288 |
-
size="lg"
|
| 289 |
-
)
|
| 290 |
-
|
| 291 |
-
with gr.Row():
|
| 292 |
-
gr.Markdown(
|
| 293 |
-
"""
|
| 294 |
-
**π‘ Tips for best results:**
|
| 295 |
-
- Be specific about your financial goal
|
| 296 |
-
- Include realistic timeframes
|
| 297 |
-
- Consider your actual risk tolerance
|
| 298 |
-
- Make sure your income > expenses for meaningful investing
|
| 299 |
-
- Country selection affects tax-advantaged account recommendations
|
| 300 |
-
"""
|
| 301 |
)
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
# Event handlers
|
| 309 |
submit_btn.click(
|
| 310 |
fn=get_investment_strategy,
|
| 311 |
inputs=[age_group, income, expenses, risk_profile, goal, timeframe, country],
|
|
@@ -326,4 +317,4 @@ if __name__ == "__main__":
|
|
| 326 |
share=False,
|
| 327 |
show_error=True,
|
| 328 |
debug=True
|
| 329 |
-
)
|
|
|
|
|
|
|
|
|
|
| 1 |
# app.py - Optimized with better timeout handling
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 192 |
except Exception as e:
|
| 193 |
return f"β **Test Error**: {str(e)}"
|
| 194 |
|
|
|
|
| 195 |
with gr.Blocks(
|
| 196 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
|
| 197 |
title="π Personal Finance Strategist",
|
|
|
|
| 204 |
border-radius: 8px;
|
| 205 |
margin: 10px 0;
|
| 206 |
}
|
| 207 |
+
.sticky-btn {
|
| 208 |
+
position: sticky;
|
| 209 |
+
top: 0;
|
| 210 |
+
z-index: 10;
|
| 211 |
+
background: white;
|
| 212 |
+
padding: 5px;
|
| 213 |
+
}
|
| 214 |
"""
|
| 215 |
) as interface:
|
| 216 |
|
| 217 |
gr.Markdown(
|
| 218 |
"""
|
| 219 |
+
# π Personal Finance Strategist
|
| 220 |
**AI-Powered Investment Strategy Generator**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
"""
|
| 222 |
)
|
| 223 |
+
|
| 224 |
+
with gr.Accordion("π€ Personal + Financial Profile", open=True):
|
| 225 |
+
with gr.Row():
|
| 226 |
+
with gr.Column():
|
| 227 |
+
age_group = gr.Dropdown(
|
| 228 |
+
choices=["20s", "30s", "40s", "50s+"],
|
| 229 |
+
label="Age Group",
|
| 230 |
+
value="30s",
|
| 231 |
+
info="Select your current age range"
|
| 232 |
+
)
|
| 233 |
+
country = gr.Dropdown(
|
| 234 |
+
choices=[
|
| 235 |
+
"United States", "Canada", "United Kingdom",
|
| 236 |
+
"Germany", "France", "Italy", "Japan", "India"
|
| 237 |
+
],
|
| 238 |
+
label="Country of Residence",
|
| 239 |
+
value="United States",
|
| 240 |
+
info="Your tax residence country"
|
| 241 |
+
)
|
| 242 |
+
income = gr.Number(
|
| 243 |
+
label="Monthly Income ($)",
|
| 244 |
+
value=6000,
|
| 245 |
+
minimum=0,
|
| 246 |
+
info="Your total monthly income before taxes"
|
| 247 |
+
)
|
| 248 |
+
expenses = gr.Number(
|
| 249 |
+
label="Monthly Expenses ($)",
|
| 250 |
+
value=4000,
|
| 251 |
+
minimum=0,
|
| 252 |
+
info="Your total monthly expenses"
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
with gr.Column():
|
| 256 |
+
risk_profile = gr.Radio(
|
| 257 |
+
choices=["Conservative", "Moderate", "Aggressive"],
|
| 258 |
+
label="Risk Tolerance",
|
| 259 |
+
value="Moderate",
|
| 260 |
+
info="How comfortable are you with investment risk?",
|
| 261 |
+
interactive=True
|
| 262 |
+
)
|
| 263 |
+
goal = gr.Textbox(
|
| 264 |
+
label="Financial Goal",
|
| 265 |
+
placeholder="e.g., buy a house, retirement, emergency fund, child's education",
|
| 266 |
+
info="What are you saving/investing for?"
|
| 267 |
+
)
|
| 268 |
+
timeframe = gr.Textbox(
|
| 269 |
+
label="Investment Timeframe",
|
| 270 |
+
placeholder="e.g., 5 years, 10 years, until retirement",
|
| 271 |
+
info="How long do you plan to invest?"
|
| 272 |
+
)
|
| 273 |
|
| 274 |
with gr.Row():
|
| 275 |
+
submit_btn = gr.Button("π Generate Investment Strategy", variant="primary", size="lg")
|
| 276 |
+
test_btn = gr.Button("π Test Service", variant="secondary", size="lg")
|
| 277 |
+
|
| 278 |
+
gr.Markdown("### π‘ Tips for best results")
|
| 279 |
+
gr.HTML("""
|
| 280 |
+
<ul style="line-height: 1.6">
|
| 281 |
+
<li>β
Be specific about your financial goal</li>
|
| 282 |
+
<li>β³ Include realistic timeframes</li>
|
| 283 |
+
<li>π Consider your actual risk tolerance</li>
|
| 284 |
+
<li>π΅ Ensure income is greater than expenses</li>
|
| 285 |
+
<li>π Country selection affects tax-advantaged advice</li>
|
| 286 |
+
</ul>
|
| 287 |
+
""")
|
| 288 |
+
|
| 289 |
+
with gr.Box():
|
| 290 |
+
output = gr.Markdown(
|
| 291 |
+
label="π Investment Strategy",
|
| 292 |
+
value="π§ Click 'Generate Investment Strategy' to get personalized recommendations!",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
)
|
| 294 |
+
|
| 295 |
+
# Optional image upload panel (currently not used in logic)
|
| 296 |
+
with gr.Accordion("πΌοΈ Upload a financial-related image (optional - future feature)", open=False):
|
| 297 |
+
img = gr.Image(label="Upload Chart or Statement", type="filepath")
|
| 298 |
+
|
| 299 |
+
# Attach event handlers
|
|
|
|
| 300 |
submit_btn.click(
|
| 301 |
fn=get_investment_strategy,
|
| 302 |
inputs=[age_group, income, expenses, risk_profile, goal, timeframe, country],
|
|
|
|
| 317 |
share=False,
|
| 318 |
show_error=True,
|
| 319 |
debug=True
|
| 320 |
+
)
|