amirhosseinkarami commited on
Commit
6010e28
·
1 Parent(s): edc613f

simplify app

Browse files
Files changed (1) hide show
  1. app.py +37 -17
app.py CHANGED
@@ -14,30 +14,50 @@ def initialize_and_tokenize(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")
 
14
  rec.tokenize_text()
15
 
16
  names = []
17
+ def recommend (movies, tok) :
18
+ initialize_and_tokenize(tok)
19
  pool = concurrent.futures.ThreadPoolExecutor(max_workers=10)
20
  futures = [pool.submit(rec.recommend_k_items, movie, 5) for movie in movies]
21
  idss = [f.result() for f in futures]
22
  ids = [id for ids in idss for id in ids]
23
  ids = list(set(ids))
24
  names = desc[desc['id'].isin(ids)]['title'].to_list()
25
+ return ', '.join(names)
26
 
27
+ demo = gr.Interface(fn=recommend,
28
+ inputs=[gr.Dropdown(choices = list(desc['title']), multiselect=True, max_choices=3, label="Movies"),
29
+ gr.Radio(["bert", "scibert", "nltk" , "none"], value="none", label="Tokenization and text preprocess")],
30
+ outputs=gr.Textbox())
 
 
 
 
 
 
 
 
 
 
 
 
31
  demo.launch()
32
 
33
+
34
+ # ===========================
35
+ # with gr.Blocks() as demo:
36
+ # gr.Markdown("Start typing below and then click **Run** to see the output.")
37
+ # with gr.Row():
38
+ # radio = gr.Radio(["bert", "scibert", "nltk" , "none"], value="none",
39
+ # label="Tokenization and text preprocess")
40
+ # btn = gr.Button("Tokenize and Preprocess")
41
+ # btn.click(fn=initialize_and_tokenize, inputs=radio)
42
+ # # demo.launch()
43
+ # # with gr.Blocks() as demo2:
44
+ # gr.Markdown("Choose 3 movies")
45
+ # with gr.Row():
46
+ # dropdown = gr.Dropdown(choices = list(desc['title']), multiselect=True, max_choices=3,
47
+ # label="Movies")
48
+ # box = gr.Textbox(lines=3, label="recs")
49
+ # btn2 = gr.Button("Recommend")
50
+ # btn2.click(fn=recommend, inputs=dropdown,outputs=[])
51
+ # gr.Markdown("rec{}".format(len(names)))
52
+ # demo.launch()
53
+
54
+ # ==========================
55
+
56
+ # with gr.Blocks() as demo :
57
+ # gr.Markdown("Start typing below and then click **Run** to see the output.")
58
+ # with gr.Row():
59
+ # radio = gr.Radio(["bert", "scibert", "nltk" , "none"], value="none",
60
+ # label="Tokenization and text preprocess")
61
+ # btn = gr.Button("Tokenize and Preprocess")
62
+ # btn.click(fn=initialize_and_tokenize, inputs=radio, outputs=[])
63
  # demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")