BalajiM commited on
Commit
d6bb049
·
verified ·
1 Parent(s): ccb3c87

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ # 1. The Database (V1 Mock Data for Madurai Market)
5
+ # We can connect this to a live web scraper later.
6
+ ev_data = {
7
+ "Model": ["Bounce Infinity E1", "TVS iQube", "Bajaj Chetak", "Ather 450X", "Ola S1 Pro", "Hero Vida V1"],
8
+ "Price (INR)": [79000, 123000, 122000, 138000, 147000, 145000],
9
+ "Real Range (km)": [85, 100, 90, 105, 143, 110],
10
+ "Top Speed (kmph)": [65, 78, 73, 90, 120, 80],
11
+ "Charging Time (Hrs)": [4.0, 4.5, 4.0, 5.5, 6.5, 6.0]
12
+ }
13
+ df = pd.DataFrame(ev_data)
14
+
15
+ # 2. The Search Logic
16
+ def recommend_ev(max_budget, min_range):
17
+ # Filter the dataframe based on user slider inputs
18
+ filtered_df = df[(df["Price (INR)"] <= max_budget) & (df["Real Range (km)"] >= min_range)]
19
+
20
+ # Sort the results so the cheapest options appear at the top
21
+ filtered_df = filtered_df.sort_values(by="Price (INR)")
22
+
23
+ # Return the clean dataframe
24
+ return filtered_df
25
+
26
+ # 3. The Frontend Architecture
27
+ # We use Gradio Blocks to make it look like a modern, enterprise dashboard
28
+ with gr.Blocks(theme=gr.themes.Soft()) as app:
29
+
30
+ gr.Markdown("# 🛵 Smart EV Tracker & Recommender")
31
+ gr.Markdown("Filter the current electric two-wheeler market based on your exact constraints.")
32
+
33
+ with gr.Row():
34
+ # Left Column: User Controls
35
+ with gr.Column(scale=1):
36
+ gr.Markdown("### Search Filters")
37
+ # Defaulting to 60k to match typical entry-level EV searches
38
+ budget_slider = gr.Slider(minimum=50000, maximum=160000, step=5000, value=90000, label="Maximum Budget (₹)")
39
+ range_slider = gr.Slider(minimum=50, maximum=150, step=5, value=75, label="Minimum Range Required (km)")
40
+ search_btn = gr.Button("Find My EV", variant="primary")
41
+
42
+ # Right Column: Data Output
43
+ with gr.Column(scale=2):
44
+ gr.Markdown("### Recommended Models")
45
+ # Gradio automatically renders Pandas Dataframes as beautiful, interactive tables
46
+ output_table = gr.Dataframe(headers=["Model", "Price (INR)", "Real Range (km)", "Top Speed (kmph)", "Charging Time (Hrs)"])
47
+
48
+ # Wire the button to the logic function
49
+ search_btn.click(fn=recommend_ev, inputs=[budget_slider, range_slider], outputs=output_table)
50
+
51
+ # Launch the app
52
+ app.launch()