Preeeeet commited on
Commit
08feed0
·
verified ·
1 Parent(s): 5b9e985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +127 -75
app.py CHANGED
@@ -1,31 +1,66 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- # Custom CSS for additional styling
5
  custom_css = """
6
  footer {visibility: hidden}
7
- h1 {
8
  text-align: center;
9
- color: #2f4f4f;
10
- font-family: 'Helvetica', sans-serif;
 
 
 
11
  }
12
- .dataframe {
13
- border-radius: 8px;
14
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
 
 
 
 
 
 
 
 
15
  }
16
- .dark .dataframe {
17
- box-shadow: 0 2px 4px rgba(255,255,255,0.1);
 
 
 
 
 
18
  }
19
  .button-primary {
20
  background: linear-gradient(45deg, #4B0082, #6A5ACD) !important;
21
  color: white !important;
22
  border: none !important;
 
 
 
 
 
 
23
  }
24
  .button-secondary {
25
  background: linear-gradient(45deg, #228B22, #32CD32) !important;
26
- color: white !important;
27
  border: none !important;
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  """
30
 
31
  # Load the Excel file
@@ -43,9 +78,9 @@ def update_city_options(province):
43
  cities = ["All"] + data[data['Province'] == province]['City'].unique().tolist()
44
  return gr.Dropdown(choices=cities, label="Select City", multiselect=True)
45
 
46
- # Filter function (same as before)
47
  def search_directory(province, cities, service_types):
48
- if not province:
49
  return pd.DataFrame(columns=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"])
50
 
51
  # Filter by province
@@ -65,7 +100,7 @@ def search_directory(province, cities, service_types):
65
  if filtered_data.empty:
66
  return pd.DataFrame(columns=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"])
67
 
68
- # Create a formatted dataframe for results
69
  filtered_data['Address'] = (
70
  filtered_data['Address 1'] + ", " +
71
  filtered_data['City'] + ", " +
@@ -84,9 +119,9 @@ def search_directory(province, cities, service_types):
84
 
85
  return result_df
86
 
87
- # Export function (same as before)
88
  def export_results_to_excel(province, cities, service_types):
89
- results_df = search_directory(province, cities, service_types)
90
  if results_df.empty:
91
  return None
92
 
@@ -94,95 +129,112 @@ def export_results_to_excel(province, cities, service_types):
94
  results_df.to_excel(filename, index=False)
95
  return filename
96
 
97
- # Build Gradio Interface with enhanced design
98
- with gr.Blocks(theme=gr.themes.Default(
99
- primary_hue="indigo",
100
- secondary_hue="emerald",
101
- neutral_hue="slate",
102
- radius_size="md",
103
- text_size="md"
104
- ), css=custom_css) as app:
 
 
 
105
 
106
  # Header Section
107
- gr.Markdown("# 🔍 Indigenous Business Directory", elem_classes="h1")
108
- gr.Markdown("Explore indigenous businesses across Canada. Select filters below to begin your search.",
109
- elem_classes="caption")
110
-
111
- # Filters Section
112
- with gr.Row():
113
- with gr.Column(scale=2):
 
 
 
114
  province_input = gr.Dropdown(
115
  label="Select Province",
116
  choices=[""] + sorted(data['Province'].unique()),
117
- interactive=True
 
118
  )
119
- with gr.Column(scale=3):
120
  city_input = gr.Dropdown(
121
- label="Select City",
122
  choices=[],
123
  multiselect=True,
124
  interactive=True
125
  )
126
-
127
- service_input = gr.Dropdown(
128
- label="Select Service Type",
129
- choices=service_types,
130
- multiselect=True,
131
- info="Select multiple services to filter"
132
- )
133
-
134
  # Action Buttons
135
  with gr.Row():
136
  search_btn = gr.Button(
137
- "Search Businesses",
138
- variant="primary",
139
  elem_classes="button-primary"
140
  )
141
  export_btn = gr.Button(
142
- "Export Results",
143
- variant="secondary",
144
  elem_classes="button-secondary"
145
  )
146
-
147
  # Results Section
148
- gr.Markdown("### Results")
149
- output = gr.Dataframe(
150
- headers=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"],
151
- interactive=False,
152
- datatype=["markdown"]*6,
153
- elem_id="results-table"
154
- )
155
-
 
 
 
156
  # Empty State
157
- gr.HTML("""
158
- <div class="empty-state" style="text-align: center; padding: 20px; color: #666;">
159
- <p>No results to display. Select filters and click 'Search Businesses' to begin.</p>
160
- </div>
161
- """, visible=False)
162
-
 
163
  # Footer
164
  gr.Markdown("---")
165
- gr.Markdown("🇨🇦 Proudly serving Canadian indigenous business community",
166
- elem_classes="footer-text")
 
 
 
167
 
168
  # Interactions
169
- province_input.change(fn=update_city_options, inputs=province_input, outputs=city_input)
 
 
 
 
 
170
  search_btn.click(
171
- fn=search_directory,
172
- inputs=[province_input, city_input, service_input],
173
- outputs=output,
174
- api_name="search"
175
  ).then(
176
- None,
177
- _js="(results) => { document.querySelector('.empty-state').style.display = results.length > 0 ? 'none' : 'block'; }"
 
178
  )
179
-
180
  export_btn.click(
181
- fn=export_results_to_excel,
182
- inputs=[province_input, city_input, service_input],
183
- outputs=gr.File(label="⬇️ Download Results"),
184
- api_name="export"
185
  )
186
 
187
  # Launch the app
188
- app.launch()
 
 
1
  import gradio as gr
2
  import pandas as pd
3
 
4
+ # Custom CSS for enhanced styling
5
  custom_css = """
6
  footer {visibility: hidden}
7
+ .app-title {
8
  text-align: center;
9
+ color: #2F4F4F;
10
+ font-size: 2.5em !important;
11
+ font-weight: 600;
12
+ margin-bottom: 0.5em !important;
13
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
14
  }
15
+ .app-description {
16
+ text-align: center;
17
+ color: #666;
18
+ margin-bottom: 2em !important;
19
+ }
20
+ .filter-section {
21
+ background: #f8f9fa;
22
+ padding: 20px;
23
+ border-radius: 12px;
24
+ margin-bottom: 2em;
25
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
26
  }
27
+ .results-section {
28
+ margin-top: 2em;
29
+ }
30
+ .dataframe {
31
+ border-radius: 8px !important;
32
+ overflow: hidden !important;
33
+ box-shadow: 0 4px 6px rgba(0,0,0,0.05) !important;
34
  }
35
  .button-primary {
36
  background: linear-gradient(45deg, #4B0082, #6A5ACD) !important;
37
  color: white !important;
38
  border: none !important;
39
+ padding: 12px 24px !important;
40
+ border-radius: 8px !important;
41
+ transition: transform 0.2s ease !important;
42
+ }
43
+ .button-primary:hover {
44
+ transform: translateY(-1px);
45
  }
46
  .button-secondary {
47
  background: linear-gradient(45deg, #228B22, #32CD32) !important;
 
48
  border: none !important;
49
  }
50
+ .empty-state {
51
+ text-align: center;
52
+ padding: 40px 20px;
53
+ background: #f8f9fa;
54
+ border-radius: 12px;
55
+ margin: 2em 0;
56
+ color: #666;
57
+ }
58
+ .footer-text {
59
+ text-align: center;
60
+ color: #666;
61
+ margin-top: 2em !important;
62
+ font-style: italic;
63
+ }
64
  """
65
 
66
  # Load the Excel file
 
78
  cities = ["All"] + data[data['Province'] == province]['City'].unique().tolist()
79
  return gr.Dropdown(choices=cities, label="Select City", multiselect=True)
80
 
81
+ # Filter function based on user input
82
  def search_directory(province, cities, service_types):
83
+ if not province:
84
  return pd.DataFrame(columns=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"])
85
 
86
  # Filter by province
 
100
  if filtered_data.empty:
101
  return pd.DataFrame(columns=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"])
102
 
103
+ # Create formatted address
104
  filtered_data['Address'] = (
105
  filtered_data['Address 1'] + ", " +
106
  filtered_data['City'] + ", " +
 
119
 
120
  return result_df
121
 
122
+ # Function to export results to Excel
123
  def export_results_to_excel(province, cities, service_types):
124
+ results_df = search_directory(province, cities, service_types)
125
  if results_df.empty:
126
  return None
127
 
 
129
  results_df.to_excel(filename, index=False)
130
  return filename
131
 
132
+ # Build Gradio Interface
133
+ with gr.Blocks(
134
+ theme=gr.themes.Default(
135
+ primary_hue="indigo",
136
+ secondary_hue="emerald",
137
+ neutral_hue="slate",
138
+ radius_size="md",
139
+ text_size="md"
140
+ ),
141
+ css=custom_css
142
+ ) as app:
143
 
144
  # Header Section
145
+ gr.Markdown("<div class='app-title'>🏢 Indigenous Business Directory</div>")
146
+ gr.Markdown(
147
+ """<div class='app-description'>
148
+ Discover and connect with Indigenous-owned businesses across Canada
149
+ </div>"""
150
+ )
151
+
152
+ # Filter Section
153
+ with gr.Row(variant="panel", elem_classes="filter-section"):
154
+ with gr.Column():
155
  province_input = gr.Dropdown(
156
  label="Select Province",
157
  choices=[""] + sorted(data['Province'].unique()),
158
+ interactive=True,
159
+ allow_custom_value=False
160
  )
 
161
  city_input = gr.Dropdown(
162
+ label="Select City",
163
  choices=[],
164
  multiselect=True,
165
  interactive=True
166
  )
167
+ service_input = gr.Dropdown(
168
+ label="Select Service Type",
169
+ choices=service_types,
170
+ multiselect=True,
171
+ interactive=True
172
+ )
173
+
 
174
  # Action Buttons
175
  with gr.Row():
176
  search_btn = gr.Button(
177
+ "🔍 Search Businesses",
178
+ variant="primary",
179
  elem_classes="button-primary"
180
  )
181
  export_btn = gr.Button(
182
+ "📤 Export Results",
183
+ variant="secondary",
184
  elem_classes="button-secondary"
185
  )
186
+
187
  # Results Section
188
+ with gr.Column(elem_classes="results-section"):
189
+ gr.Markdown("### Search Results")
190
+ output = gr.Dataframe(
191
+ headers=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"],
192
+ datatype=["str", "str", "str", "str", "str", "str"],
193
+ interactive=False,
194
+ row_count=(10, "paginated"),
195
+ wrap=True,
196
+ elem_id="results-table"
197
+ )
198
+
199
  # Empty State
200
+ empty_state = gr.HTML(
201
+ """<div class='empty-state'>
202
+ <h3>No results found</h3>
203
+ <p>Try adjusting your filters or search criteria</p>
204
+ </div>"""
205
+ )
206
+
207
  # Footer
208
  gr.Markdown("---")
209
+ gr.Markdown(
210
+ """<div class='footer-text'>
211
+ 🇨🇦 Proudly supporting Indigenous businesses in Canada
212
+ </div>"""
213
+ )
214
 
215
  # Interactions
216
+ province_input.change(
217
+ fn=update_city_options,
218
+ inputs=province_input,
219
+ outputs=city_input
220
+ )
221
+
222
  search_btn.click(
223
+ fn=search_directory,
224
+ inputs=[province_input, city_input, service_input],
225
+ outputs=output
 
226
  ).then(
227
+ lambda x: gr.HTML.update(visible=len(x) == 0),
228
+ inputs=output,
229
+ outputs=empty_state
230
  )
231
+
232
  export_btn.click(
233
+ fn=export_results_to_excel,
234
+ inputs=[province_input, city_input, service_input],
235
+ outputs=gr.File(label="⬇️ Download Results")
 
236
  )
237
 
238
  # Launch the app
239
+ if __name__ == "__main__":
240
+ app.launch()