amirhosseinkarami commited on
Commit
edc613f
·
1 Parent(s): 0c1b0dd

Updata app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -3
app.py CHANGED
@@ -1,10 +1,43 @@
1
  import gradio
 
 
 
2
  from App.tfidfrecommender import TfidfRecommender
3
 
4
  import gradio as gr
5
 
6
- def image_classifier(inp):
7
- return {'cat': 0.3, 'dog': 0.7}
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  demo.launch()
 
 
 
1
  import gradio
2
+ import pandas as pd
3
+ import concurrent.futures
4
+
5
  from App.tfidfrecommender import TfidfRecommender
6
 
7
  import gradio as gr
8
 
9
+ desc = pd.read_csv('App/data/descriptions.csv')
10
+
11
+ rec = TfidfRecommender(desc, 'id', 'description' , "none")
12
+ def initialize_and_tokenize(tokenizer):
13
+ rec.tokenization_method = tokenizer
14
+ rec.tokenize_text()
15
+
16
+ names = []
17
+ def recommend (movies) :
18
+ pool = concurrent.futures.ThreadPoolExecutor(max_workers=10)
19
+ futures = [pool.submit(rec.recommend_k_items, movie, 5) for movie in movies]
20
+ idss = [f.result() for f in futures]
21
+ ids = [id for ids in idss for id in ids]
22
+ ids = list(set(ids))
23
+ names = desc[desc['id'].isin(ids)]['title'].to_list()
24
 
25
+
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("Start typing below and then click **Run** to see the output.")
28
+ with gr.Row():
29
+ radio = gr.Radio(["bert", "scibert", "nltk" , "none"], value="none",
30
+ label="Tokenization and text preprocess")
31
+ btn = gr.Button("Tokenize and Preprocess")
32
+ btn.click(fn=initialize_and_tokenize, inputs=radio, outputs=[])
33
+
34
+ gr.Markdown("Choose 3 movies")
35
+ with gr.Row():
36
+ dropdown = gr.Dropdown(choices = list(desc['title']), multiselect=True, max_choices=3,
37
+ label="Movies")
38
+ btn2 = gr.Button("Recommend")
39
+ btn2.click(fn=recommend, inputs=dropdown,outputs=[])
40
+ gr.Markdown("rec{}".format(len(names)))
41
  demo.launch()
42
+
43
+ # demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")