FreshP commited on
Commit
d0631f5
1 Parent(s): 36a71ae

Added traditional interface tab

Browse files
Files changed (1) hide show
  1. app.py +31 -27
app.py CHANGED
@@ -2,13 +2,10 @@ import gradio as gr
2
  import numpy as np
3
  import pandas as pd
4
  from datetime import datetime
5
- import os
6
 
7
  from huggingface_hub import hf_hub_url, cached_download
8
  from gensim.models.fasttext import load_facebook_model
9
 
10
- ACCESS_KEY = os.environ.get("ACCESS_KEY")
11
-
12
  # download model from huggingface hub
13
  url = hf_hub_url(repo_id="simonschoe/call2vec", filename="model.bin")
14
  cached_download(url)
@@ -24,7 +21,7 @@ def process(_input, topn):
24
 
25
  _input = [s for s in _input if s]
26
 
27
- if _input[0] != ACCESS_KEY:
28
  with open('log.txt', 'a') as f:
29
  f.write(str(datetime.now()) + '+++' + '___'.join(_input) + '\n')
30
 
@@ -41,7 +38,7 @@ def process(_input, topn):
41
  frequencies = [model.wv.get_vecattr(nn[0], 'count') for nn in nearest_neighbors]
42
 
43
  result = pd.DataFrame([(a[0],a[1],b) for a,b in zip(nearest_neighbors, frequencies)], columns=['Token', 'Cosine Similarity', 'Frequency'])
44
- if _input[0] == ACCESS_KEY:
45
  with open('log.txt', 'r') as f:
46
  prompts = f.readlines()
47
  prompts = [p.strip().split('+++') for p in prompts]
@@ -53,33 +50,40 @@ def save(df):
53
  df.to_csv('result.csv')
54
  return 'result.csv'
55
 
56
- demo = gr.Blocks(theme="dark")
57
 
58
  with demo:
59
  gr.Markdown("# Call2Vec")
60
  gr.Markdown("## Earnings call transformation project")
61
- with gr.Row():
62
- with gr.Column():
63
- similar_radio = gr.Radio(label="Single or multiple input prompts", value="Single", choices=["Single", "Multiple"])
64
- n_output = gr.Slider(minimum=5, maximum=50, step=1)
65
- gr.Markdown(
66
- """### Example prompts:
67
- - Example 1
68
- - Example 2
69
- """
70
- )
71
- with gr.Column():
72
- text_input = gr.Textbox(lines=1)
73
  with gr.Row():
74
- compute_button = gr.Button("Compute")
75
- df_output = gr.Dataframe(interactive=False)
76
- file_out = gr.File(interactive=False)
77
- with gr.Column():
78
- gr.Markdown("""
79
- ### Project Description
80
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.""")
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- compute_button.click(process, inputs=[text_input, n_output], outputs=[df_output, file_out])
83
- similar_radio.change(lambda x: "\n\n\n\n\n\n\n" if x=='Multiple' else "", inputs=[similar_radio], outputs=[text_input])
 
 
 
 
 
84
 
85
  demo.launch()
 
2
  import numpy as np
3
  import pandas as pd
4
  from datetime import datetime
 
5
 
6
  from huggingface_hub import hf_hub_url, cached_download
7
  from gensim.models.fasttext import load_facebook_model
8
 
 
 
9
  # download model from huggingface hub
10
  url = hf_hub_url(repo_id="simonschoe/call2vec", filename="model.bin")
11
  cached_download(url)
 
21
 
22
  _input = [s for s in _input if s]
23
 
24
+ if _input[0] != "secret_result_key":
25
  with open('log.txt', 'a') as f:
26
  f.write(str(datetime.now()) + '+++' + '___'.join(_input) + '\n')
27
 
 
38
  frequencies = [model.wv.get_vecattr(nn[0], 'count') for nn in nearest_neighbors]
39
 
40
  result = pd.DataFrame([(a[0],a[1],b) for a,b in zip(nearest_neighbors, frequencies)], columns=['Token', 'Cosine Similarity', 'Frequency'])
41
+ if _input[0] == "secret_result_key":
42
  with open('log.txt', 'r') as f:
43
  prompts = f.readlines()
44
  prompts = [p.strip().split('+++') for p in prompts]
 
50
  df.to_csv('result.csv')
51
  return 'result.csv'
52
 
53
+ demo = gr.Blocks()
54
 
55
  with demo:
56
  gr.Markdown("# Call2Vec")
57
  gr.Markdown("## Earnings call transformation project")
58
+ with gr.Tabs():
59
+ with gr.TabItem(label='Block Interface'):
 
 
 
 
 
 
 
 
 
 
60
  with gr.Row():
61
+ with gr.Column():
62
+ similar_radio = gr.Radio(label="Single or multiple input prompts", value="Single", choices=["Single", "Multiple"])
63
+ n_output = gr.Slider(minimum=5, maximum=50, step=1)
64
+ gr.Markdown(
65
+ """### Example prompts:
66
+ - Example 1
67
+ - Example 2
68
+ """
69
+ )
70
+ with gr.Column():
71
+ text_input = gr.Textbox(lines=1)
72
+ with gr.Row():
73
+ compute_button = gr.Button("Compute")
74
+ df_output = gr.Dataframe(interactive=False)
75
+ file_out = gr.File(interactive=False)
76
+ with gr.Column():
77
+ gr.Markdown("""
78
+ ### Project Description
79
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.""")
80
 
81
+ compute_button.click(process, inputs=[text_input, n_output], outputs=[df_output, file_out])
82
+ similar_radio.change(lambda x: "\n\n\n\n\n\n\n" if x=='Multiple' else "", inputs=[similar_radio], outputs=[text_input])
83
+ with gr.TabItem('Traditional Interface'):
84
+ gr.Interface(process, inputs=[gr.Textbox(lines=3), gr.Slider(minimum=5, maximum=50, step=1)],
85
+ outputs=[gr.Dataframe(interactive=False), gr.File(interactive=False)],
86
+ examples=[["Test example", 5],
87
+ ["Multiple prompts\nexample", 7]])
88
 
89
  demo.launch()