Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,8 @@ from utils.formatters import (
|
|
| 24 |
create_trend_line_chart,
|
| 25 |
create_card_performance_chart)
|
| 26 |
from utils.llm_explainer import get_llm_explainer
|
|
|
|
|
|
|
| 27 |
import config
|
| 28 |
|
| 29 |
CARDS_FILE = os.path.join(os.path.dirname(__file__), "data", "cards.json")
|
|
@@ -704,6 +706,7 @@ def create_agent_recommendation_chart_enhanced(result: Dict) -> go.Figure:
|
|
| 704 |
|
| 705 |
client = RewardPilotClient(config.ORCHESTRATOR_URL)
|
| 706 |
llm = get_llm_explainer()
|
|
|
|
| 707 |
|
| 708 |
def get_recommendation(
|
| 709 |
user_id: str,
|
|
@@ -785,11 +788,11 @@ def get_recommendation_with_ai(user_id, merchant, category, amount):
|
|
| 785 |
return
|
| 786 |
|
| 787 |
data = normalize_recommendation_data(result.get('data', {}))
|
| 788 |
-
|
| 789 |
ai_explanation = ""
|
| 790 |
-
if config.
|
| 791 |
try:
|
| 792 |
-
ai_explanation =
|
| 793 |
card=data['recommended_card'],
|
| 794 |
rewards=data['rewards_earned'],
|
| 795 |
rewards_rate=data['rewards_rate'],
|
|
@@ -800,10 +803,11 @@ def get_recommendation_with_ai(user_id, merchant, category, amount):
|
|
| 800 |
annual_potential=data['annual_potential'],
|
| 801 |
alternatives=data['alternatives']
|
| 802 |
)
|
|
|
|
| 803 |
except Exception as e:
|
| 804 |
-
print(f"
|
| 805 |
ai_explanation = ""
|
| 806 |
-
|
| 807 |
output = f"""
|
| 808 |
## π― Recommendation for ${amount:.2f} at {merchant}
|
| 809 |
|
|
@@ -1850,6 +1854,13 @@ with gr.Blocks(
|
|
| 1850 |
minimum=0.01,
|
| 1851 |
step=0.01
|
| 1852 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1853 |
|
| 1854 |
date_input = gr.Textbox(
|
| 1855 |
label="π
Transaction Date (Optional)",
|
|
|
|
| 24 |
create_trend_line_chart,
|
| 25 |
create_card_performance_chart)
|
| 26 |
from utils.llm_explainer import get_llm_explainer
|
| 27 |
+
from utils.gemini_explainer import get_gemini_explainer
|
| 28 |
+
|
| 29 |
import config
|
| 30 |
|
| 31 |
CARDS_FILE = os.path.join(os.path.dirname(__file__), "data", "cards.json")
|
|
|
|
| 706 |
|
| 707 |
client = RewardPilotClient(config.ORCHESTRATOR_URL)
|
| 708 |
llm = get_llm_explainer()
|
| 709 |
+
gemini = get_gemini_explainer()
|
| 710 |
|
| 711 |
def get_recommendation(
|
| 712 |
user_id: str,
|
|
|
|
| 788 |
return
|
| 789 |
|
| 790 |
data = normalize_recommendation_data(result.get('data', {}))
|
| 791 |
+
|
| 792 |
ai_explanation = ""
|
| 793 |
+
if config.USE_GEMINI and gemini.enabled:
|
| 794 |
try:
|
| 795 |
+
ai_explanation = gemini.explain_recommendation(
|
| 796 |
card=data['recommended_card'],
|
| 797 |
rewards=data['rewards_earned'],
|
| 798 |
rewards_rate=data['rewards_rate'],
|
|
|
|
| 803 |
annual_potential=data['annual_potential'],
|
| 804 |
alternatives=data['alternatives']
|
| 805 |
)
|
| 806 |
+
ai_explanation = f"π€ **Powered by Google Gemini**\n\n{ai_explanation}"
|
| 807 |
except Exception as e:
|
| 808 |
+
print(f"Gemini explanation failed: {e}")
|
| 809 |
ai_explanation = ""
|
| 810 |
+
|
| 811 |
output = f"""
|
| 812 |
## π― Recommendation for ${amount:.2f} at {merchant}
|
| 813 |
|
|
|
|
| 1854 |
minimum=0.01,
|
| 1855 |
step=0.01
|
| 1856 |
)
|
| 1857 |
+
|
| 1858 |
+
with gr.Accordion("π€ AI Settings", open=False):
|
| 1859 |
+
use_gemini = gr.Checkbox(
|
| 1860 |
+
label="Use Google Gemini for explanations",
|
| 1861 |
+
value=False,
|
| 1862 |
+
info="Switch to Gemini 1.5 Pro for AI insights"
|
| 1863 |
+
)
|
| 1864 |
|
| 1865 |
date_input = gr.Textbox(
|
| 1866 |
label="π
Transaction Date (Optional)",
|