FreshP commited on
Commit
aae3e83
1 Parent(s): 7e21fe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -33
app.py CHANGED
@@ -3,6 +3,7 @@ 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
@@ -18,11 +19,11 @@ model = load_facebook_model(cached_download(url))
18
 
19
  def process(_input, topn):
20
 
21
- # convert input to lower, replace whitespaces by underscores
22
- _input = _input.strip().lower().replace(' ', '_')
23
- _input = _input.split('\n')
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:
@@ -47,7 +48,7 @@ def process(_input, topn):
47
  prompts = [p.strip().split('+++') for p in prompts]
48
  result = pd.DataFrame(prompts, columns=['Time', 'Prompt'])
49
  result.to_csv('result.csv')
50
- return result, 'result.csv'
51
 
52
  def save(df):
53
  df.to_csv('result.csv')
@@ -58,35 +59,28 @@ demo = gr.Blocks()
58
  with demo:
59
  gr.Markdown("# Call2Vec")
60
  gr.Markdown("## Earnings call transformation project")
61
- with gr.Tabs():
62
- with gr.TabItem(label='Block Interface'):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  with gr.Row():
64
- with gr.Column():
65
- similar_radio = gr.Radio(label="Single or multiple input prompts", value="Single", choices=["Single", "Multiple"])
66
- n_output = gr.Slider(minimum=5, maximum=50, step=1)
67
- gr.Markdown(
68
- """### Example prompts:
69
- - Example 1
70
- - Example 2
71
- """
72
- )
73
- with gr.Column():
74
- text_input = gr.Textbox(lines=1)
75
- with gr.Row():
76
- compute_button = gr.Button("Compute")
77
- df_output = gr.Dataframe(interactive=False)
78
- file_out = gr.File(interactive=False)
79
- with gr.Column():
80
- gr.Markdown("""
81
- ### Project Description
82
- 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.""")
83
 
84
- compute_button.click(process, inputs=[text_input, n_output], outputs=[df_output, file_out])
85
- similar_radio.change(lambda x: "\n\n\n\n\n\n\n" if x=='Multiple' else "", inputs=[similar_radio], outputs=[text_input])
86
- with gr.TabItem('Traditional Interface'):
87
- gr.Interface(process, inputs=[gr.Textbox(lines=3), gr.Slider(minimum=5, maximum=50, step=1)],
88
- outputs=[gr.Dataframe(interactive=False), gr.File(interactive=False)],
89
- examples=[["Test example", 5],
90
- ["Multiple prompts\nexample", 7]])
91
 
92
  demo.launch()
 
3
  import pandas as pd
4
  from datetime import datetime
5
  import os
6
+ import re
7
 
8
  from huggingface_hub import hf_hub_url, cached_download
9
  from gensim.models.fasttext import load_facebook_model
 
19
 
20
  def process(_input, topn):
21
 
22
+ # split by delimiting characters
23
+ _input = re.split('[,;\n]', _input)
 
24
 
25
+ # convert input to lower, replace whitespaces by underscores
26
+ _input = [s.strip().lower().replace(' ', '_') for s in _input if s]
27
 
28
  if _input[0] != ACCESS_KEY:
29
  with open('log.txt', 'a') as f:
 
48
  prompts = [p.strip().split('+++') for p in prompts]
49
  result = pd.DataFrame(prompts, columns=['Time', 'Prompt'])
50
  result.to_csv('result.csv')
51
+ return result, 'result.csv', '\n'.join(_input)
52
 
53
  def save(df):
54
  df.to_csv('result.csv')
 
59
  with demo:
60
  gr.Markdown("# Call2Vec")
61
  gr.Markdown("## Earnings call transformation project")
62
+ with gr.Row():
63
+ with gr.Column():
64
+ gr.Markdown("""
65
+ #### Project Description
66
+ 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.""")
67
+ gr.Markdown(
68
+ """#### App usage:
69
+ Add your input prompts to the text field on the right. To use multiple input prompts at once separate
70
+ them by comma, semicolon or a new line
71
+ ##### Examples
72
+ - Climate change
73
+ - Financial risk, energy dependency, climate neutrality
74
+ """
75
+ )
76
+ with gr.Column():
77
+ text_input = gr.Textbox(lines=1)
78
  with gr.Row():
79
+ n_output = gr.Slider(minimum=5, maximum=50, step=1)
80
+ compute_button = gr.Button("Compute")
81
+ df_output = gr.Dataframe(interactive=False)
82
+ file_out = gr.File(interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ compute_button.click(process, inputs=[text_input, n_output], outputs=[df_output, file_out, text_input])
 
 
 
 
 
 
85
 
86
  demo.launch()