Delete ui
Browse files- ui/gradio_interface.py +0 -160
ui/gradio_interface.py
DELETED
|
@@ -1,160 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from agents.chat import chat_with_gemini
|
| 3 |
-
from agents.compare import compare_selected_cards
|
| 4 |
-
from app import all_card_names,all_card_lookup
|
| 5 |
-
from recommender.recommender import recommend_cards_gradio
|
| 6 |
-
|
| 7 |
-
# Interface with Tabs
|
| 8 |
-
with gr.Blocks() as demo:
|
| 9 |
-
gr.Markdown("# Credit Card Recommender")
|
| 10 |
-
gr.Markdown("Get personalized credit card suggestions based on your lifestyle and eligibility.")
|
| 11 |
-
|
| 12 |
-
with gr.Tabs():
|
| 13 |
-
|
| 14 |
-
with gr.Tab(" Get Recommendations"):
|
| 15 |
-
with gr.Row():
|
| 16 |
-
user_query = gr.Textbox(
|
| 17 |
-
label="Enter your query",
|
| 18 |
-
info="E.g., 'Best cards for international travel' or 'I want cashback cards with lounge access'"
|
| 19 |
-
)
|
| 20 |
-
preferences = gr.CheckboxGroup(
|
| 21 |
-
choices=["Cashback", "Travel Rewards", "Fuel Benefits", "International Lounge access",
|
| 22 |
-
"Domestic Lounge access", "Railway benefits", "Dining", "Shopping"],
|
| 23 |
-
label="Credit card categories:",
|
| 24 |
-
info="Select the features or benefits you want from your credit card"
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
with gr.Accordion("Eligibility filters menu", open=False):
|
| 28 |
-
with gr.Row():
|
| 29 |
-
income = gr.Slider(
|
| 30 |
-
minimum=1, maximum=60, step=1,
|
| 31 |
-
label="Annual Income (LPA) Minimum requirement is 2.5",
|
| 32 |
-
info="Helps filter cards based on your income eligibility (in Lakhs Per Annum)"
|
| 33 |
-
)
|
| 34 |
-
cibil = gr.Slider(
|
| 35 |
-
minimum=300, maximum=900, step=10,
|
| 36 |
-
label="CIBIL Score",
|
| 37 |
-
info="Most of the cards requires a credit score of 700+"
|
| 38 |
-
)
|
| 39 |
-
age = gr.Slider(
|
| 40 |
-
minimum=18, maximum=75, step=1,
|
| 41 |
-
label="Age",
|
| 42 |
-
info="Some cards have minimum and maximum age eligibility"
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
with gr.Row():
|
| 46 |
-
min_joining_fee = gr.Number(
|
| 47 |
-
label="Min Joining Fee (₹)", value=0,
|
| 48 |
-
info="Minimum one-time fee to get the card"
|
| 49 |
-
)
|
| 50 |
-
max_joining_fee = gr.Number(
|
| 51 |
-
label="Max Joining Fee (₹)", value=150000,
|
| 52 |
-
info="Maximum one-time fee to get the card"
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
with gr.Row():
|
| 56 |
-
min_annual_fee = gr.Number(
|
| 57 |
-
label="Min Annual Fee (₹)", value=0,
|
| 58 |
-
info="Minimum yearly fee to be paid"
|
| 59 |
-
)
|
| 60 |
-
max_annual_fee = gr.Number(
|
| 61 |
-
label="Max Annual Fee (₹)", value=150000,
|
| 62 |
-
info="Maximum yearly fee to be paid"
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
use_eligibility = gr.Checkbox(
|
| 67 |
-
label="Apply Eligibility Filter", value=False,
|
| 68 |
-
info="Enable this to get recommendations of the cards only for which you are eligible for"
|
| 69 |
-
)
|
| 70 |
-
include_cobranded = gr.Checkbox(
|
| 71 |
-
label="Include Co-branded Cards", value=True,
|
| 72 |
-
info="Include cards that are co-branded with airlines, retailers, etc."
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
submit_btn = gr.Button("Recommend Cards", variant='primary')
|
| 76 |
-
|
| 77 |
-
top_card_html = gr.HTML()
|
| 78 |
-
card_df = gr.Dataframe(headers=["Card Name", "Matched Features", "Description"])
|
| 79 |
-
card_file = gr.File(label="Download Full Recommendations (CSV)")
|
| 80 |
-
|
| 81 |
-
with gr.Tab(" Compare Cards"):
|
| 82 |
-
gr.Markdown("### Compare Recommended Cards")
|
| 83 |
-
compare_checkboxes = gr.CheckboxGroup(
|
| 84 |
-
choices=[], label="Select 2 or more cards to compare",
|
| 85 |
-
info="Pick 2+ cards from the recommended list to see a comparison"
|
| 86 |
-
)
|
| 87 |
-
compare_output = gr.HTML(value="<div style='min-height:100px'></div>", visible=True)
|
| 88 |
-
compare_btn = gr.Button("Compare Selected Cards", variant='primary')
|
| 89 |
-
|
| 90 |
-
gr.Markdown("### Compare Any Cards from Full List")
|
| 91 |
-
full_compare_dropdown = gr.Dropdown(
|
| 92 |
-
choices=all_card_names, multiselect=True, label="Select any 2+ cards",
|
| 93 |
-
info="Manually compare any cards from the full database"
|
| 94 |
-
)
|
| 95 |
-
full_compare_btn = gr.Button("Compare Selected Cards", variant='primary')
|
| 96 |
-
full_compare_output = gr.HTML(value="<div style='min-height:100px'></div>", visible=True)
|
| 97 |
-
|
| 98 |
-
with gr.Tab(" Ask Follow-up Questions"):
|
| 99 |
-
gr.Markdown("### Ask any follow-up question ")
|
| 100 |
-
chatbot = gr.Chatbot(type='messages')
|
| 101 |
-
user_query_for_chat = gr.Textbox(
|
| 102 |
-
label="Enter your question",
|
| 103 |
-
info="Ask follow-ups like 'Which card has better travel insurance?' or 'Which card has less annual fee'"
|
| 104 |
-
)
|
| 105 |
-
submit_query_btn = gr.Button("Submit Query", variant='primary')
|
| 106 |
-
|
| 107 |
-
card_names_state = gr.State()
|
| 108 |
-
card_lookup_state = gr.State()
|
| 109 |
-
chat_history = gr.State([])
|
| 110 |
-
query = gr.State([])
|
| 111 |
-
|
| 112 |
-
def wrapped_recommend_cards(user_query, preferences, income, cibil, age, min_joining_fee, max_joining_fee,
|
| 113 |
-
min_annual_fee, max_annual_fee, use_eligibility,include_cobranded):
|
| 114 |
-
top_html, df, file, card_names, card_lookup, direct_query = recommend_cards_gradio(
|
| 115 |
-
user_query, preferences, income, cibil, age, min_joining_fee, max_joining_fee,
|
| 116 |
-
min_annual_fee, max_annual_fee, use_eligibility,include_cobranded
|
| 117 |
-
)
|
| 118 |
-
df_label = f"Found {len(card_names)} cards"
|
| 119 |
-
return top_html, gr.update(value=df, label=df_label), file, card_names, card_lookup, gr.update(choices=card_names, value=[]), direct_query
|
| 120 |
-
|
| 121 |
-
submit_btn.click(
|
| 122 |
-
fn=wrapped_recommend_cards,
|
| 123 |
-
inputs=[user_query, preferences, income, cibil, age, min_joining_fee, max_joining_fee,
|
| 124 |
-
min_annual_fee, max_annual_fee, use_eligibility,include_cobranded],
|
| 125 |
-
outputs=[top_card_html, card_df, card_file, card_names_state, card_lookup_state, compare_checkboxes,query]
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
compare_btn.click(
|
| 129 |
-
fn=compare_selected_cards,
|
| 130 |
-
inputs=[compare_checkboxes, card_lookup_state],
|
| 131 |
-
outputs=compare_output
|
| 132 |
-
)
|
| 133 |
-
|
| 134 |
-
full_compare_btn.click(
|
| 135 |
-
fn=lambda selected: compare_selected_cards(selected, all_card_lookup),
|
| 136 |
-
inputs=[full_compare_dropdown],
|
| 137 |
-
outputs=full_compare_output
|
| 138 |
-
)
|
| 139 |
-
|
| 140 |
-
submit_query_btn.click(
|
| 141 |
-
fn=chat_with_gemini,
|
| 142 |
-
inputs=[query,user_query_for_chat, chat_history, card_lookup_state],
|
| 143 |
-
outputs=[chatbot, chat_history]
|
| 144 |
-
).then(
|
| 145 |
-
lambda: gr.update(value=""),
|
| 146 |
-
inputs=[],
|
| 147 |
-
outputs=[user_query_for_chat]
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
-
#for submitting using enter button
|
| 151 |
-
user_query_for_chat.submit(
|
| 152 |
-
fn=chat_with_gemini,
|
| 153 |
-
inputs=[query, user_query_for_chat, chat_history, card_lookup_state],
|
| 154 |
-
outputs=[chatbot, chat_history],
|
| 155 |
-
show_progress=True
|
| 156 |
-
).then(
|
| 157 |
-
lambda: gr.update(value=""),
|
| 158 |
-
inputs=[],
|
| 159 |
-
outputs=[user_query_for_chat]
|
| 160 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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