Tanishka14 commited on
Commit
13cb787
·
1 Parent(s): 9390467

Update Gradio UI

Browse files
Files changed (1) hide show
  1. app.py +2 -47
app.py CHANGED
@@ -5,54 +5,9 @@
5
  #!/usr/bin/env python
6
  # coding: utf-8
7
 
8
- import gradio as gr
9
- from content_based import recommend_products as content_reco
10
- from collaborative import collaborative_ui, user_id_list
11
-
12
- # Helper to render a horizontal product grid as HTML
13
- def render_horizontal_grid(products_list):
14
- """
15
- products_list: list of dicts with at least 'Product Url' and 'Name'
16
- """
17
- html = '<div style="display:flex; flex-wrap: wrap;">'
18
- for p in products_list:
19
- html += f'''
20
- <div style="margin:5px; text-align:center; width:150px;">
21
- <img src="{p['Product Url']}" width="120" style="display:block; margin:auto;"><br>
22
- <span>{p['Name']}</span>
23
- </div>
24
- '''
25
- html += '</div>'
26
- return html
27
-
28
- # Wrappers to get data from your recommenders and convert to HTML
29
- def content_based_wrapper(product_name):
30
- recommended = content_reco(product_name) # should return list of dicts
31
- return render_horizontal_grid(recommended)
32
-
33
- def collaborative_wrapper(user_id):
34
- recommended = collaborative_ui(user_id) # should return list of dicts
35
- return render_horizontal_grid(recommended)
36
-
37
- # Gradio interface
38
- with gr.Blocks() as demo:
39
- gr.Markdown("## 🛍️ Product Recommendation System")
40
-
41
- with gr.Tab("Content-Based Recommender"):
42
- product_input = gr.Textbox(label="Enter a Product Name")
43
- content_output = gr.HTML(label="Top Recommendations")
44
- product_input.submit(fn=content_based_wrapper, inputs=product_input, outputs=content_output)
45
-
46
- with gr.Tab("Collaborative Filtering Recommender"):
47
- user_dropdown = gr.Dropdown(choices=user_id_list, label="Select User ID")
48
- collaborative_output = gr.HTML(label="Collaborative Recommendations")
49
- user_dropdown.change(fn=collaborative_wrapper, inputs=user_dropdown, outputs=collaborative_output)
50
-
51
- if __name__ == "__main__":
52
- demo.launch()
53
 
54
 
55
- '''import gradio as gr
56
  from content_based import recommend_products
57
  from collaborative import collaborative_ui
58
  from collaborative import user_id_list
@@ -71,7 +26,7 @@ with gr.Blocks() as demo:
71
  user_dropdown.change(fn=collaborative_ui, inputs=user_dropdown, outputs=collaborative_output)
72
 
73
  if __name__ == "__main__":
74
- demo.launch()'''
75
 
76
  # In[ ]:
77
 
 
5
  #!/usr/bin/env python
6
  # coding: utf-8
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
+ import gradio as gr
11
  from content_based import recommend_products
12
  from collaborative import collaborative_ui
13
  from collaborative import user_id_list
 
26
  user_dropdown.change(fn=collaborative_ui, inputs=user_dropdown, outputs=collaborative_output)
27
 
28
  if __name__ == "__main__":
29
+ demo.launch()
30
 
31
  # In[ ]:
32