simonschoe commited on
Commit
c75d824
β€’
1 Parent(s): 27b2a2c

app redesign

Browse files
Files changed (1) hide show
  1. app.py +44 -39
app.py CHANGED
@@ -9,7 +9,7 @@ classifier = pipeline("text-classification", model="simonschoe/TransformationTra
9
  explainer = SequenceClassificationExplainer(classifier.model, classifier.tokenizer)
10
 
11
  legend = """
12
- <div style="text-align: center; display: block; margin-left: auto; margin-right: auto; border-top: 1px solid; margin-top: 5px; padding-top: 5px;"><b>Legend: </b><span style="display: inline-block; width: 10px; height: 10px; border: 1px solid; background-color: hsl(0, 75%, 60%)"></span> Generic <span style="display: inline-block; width: 10px; height: 10px; border: 1px solid; background-color: hsl(120, 75%, 50%)"></span> Transformation </div>
13
  """
14
 
15
  def classify(_input):
@@ -22,7 +22,7 @@ def classify(_input):
22
  score = 1 - score
23
 
24
  # getting visualization
25
- attributions = explainer(_input)
26
  html = explainer.visualize().__html__()
27
 
28
  soup = BeautifulSoup(html, 'html.parser')
@@ -32,42 +32,39 @@ def classify(_input):
32
  result_html = explanation + legend
33
  return round(score, 4), result_html
34
 
35
- app = gr.Blocks()
36
 
37
  with app:
38
  gr.Markdown(
39
  """
40
- # Transformation Talk Classifier
41
  ## Detect Transformation-Related Sentences in Quarterly Earnings Calls
42
  """
43
  )
44
- with gr.Row():
45
- with gr.Column():
46
- text_in = gr.Textbox(lines=1, placeholder="Insert text", label="Input Sentence")
47
  with gr.Row():
48
- compute_bt = gr.Button("Classify")
49
- score_out = gr.Number(label="Score", interactive=False)
50
- html_out = gr.HTML(label="Explanation")
51
- gr.Examples(
52
- examples=[
53
- ["If we look at the plans for 2018, it is to introduce 650 new products, which is an absolute all- time high."],
54
- ["We have been doing kind of an integrated campaign, so it's TV, online, we do the Google Ad Words - all those different elements together."],
55
- ["So that turned out to be beneficial for us, and I think, we'll just see how the market and interest rates move over the course of the year,"]
56
- ],
57
- label="Examples (click to start detection)",
58
- inputs=[text_in],
59
- outputs=[score_out, html_out],
60
- fn=classify,
61
- run_on_click=True,
62
- cache_examples=False
63
- )
64
- with gr.Column():
65
- gr.Markdown(
66
- """
67
- #### Project Description
68
- 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.
69
- """
70
- )
71
  gr.Markdown(
72
  """
73
  #### App usage
@@ -75,16 +72,24 @@ with app:
75
  It returns a confidence score that indicates the probability of the sentence containing a discussion on transformation activities. A value of 1 (0) signals a high confidence of the sentence being transformation-related (generic). A score in the range of [0.25; 0.75] implies that the model is rather undecided about the correct label.
76
  In addition, the app returns the tokenized version of the sentence, alongside word importances that are indicated by color codes. Those visuals illustrates the ability of the context-aware classifier to simultaneously pay attention to various parts in the input sentence to derive a final label.
77
  """
 
 
 
 
 
 
 
78
  )
79
- gr.Markdown(
80
- """
81
- <p style="text-align: center;">
82
- TIClassifier by X and Y
83
- <br>
84
- <img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=simonschoe.TIC&left_color=green&right_color=blue" style="display: block; margin-left: auto; margin-right: auto;"/>
85
- </p>
86
- """
87
- )
 
88
  compute_bt.click(classify, inputs=[text_in], outputs=[score_out, html_out])
89
 
90
 
 
9
  explainer = SequenceClassificationExplainer(classifier.model, classifier.tokenizer)
10
 
11
  legend = """
12
+ <div style="text-align: left; display: block; margin-left: auto; margin-right: auto; border-top: 1px solid; margin-top: 5px; padding-top: 5px;"><b>Legend:&emsp;</b><span style="display: inline-block; width: 10px; height: 10px; border: 1px solid; background-color: hsl(0, 75%, 60%)"></span> No Transformation Talk&emsp;<span style="display: inline-block; width: 10px; height: 10px; border: 1px solid; background-color: hsl(120, 75%, 50%)"></span> Transformation Talk</div>
13
  """
14
 
15
  def classify(_input):
 
22
  score = 1 - score
23
 
24
  # getting visualization
25
+ attributions = explainer(_input, class_name='LABEL_1')
26
  html = explainer.visualize().__html__()
27
 
28
  soup = BeautifulSoup(html, 'html.parser')
 
32
  result_html = explanation + legend
33
  return round(score, 4), result_html
34
 
35
+ app = gr.Blocks(theme=gr.themes.Default(), css='#component-0 {max-width: 730px; margin: auto; padding-top: 1.5rem}')
36
 
37
  with app:
38
  gr.Markdown(
39
  """
40
+ # Transformation Talk
41
  ## Detect Transformation-Related Sentences in Quarterly Earnings Calls
42
  """
43
  )
44
+
45
+ with gr.Tabs() as tabs:
46
+ with gr.TabItem("πŸ” Model", id=0):
47
  with gr.Row():
48
+ with gr.Column():
49
+ text_in = gr.Textbox(lines=1, placeholder="Insert text here", label="Input Sentence")
50
+ with gr.Row():
51
+ compute_bt = gr.Button("Classify")
52
+ score_out = gr.Number(label="Score", interactive=False)
53
+ html_out = gr.HTML(label="Explanation")
54
+ gr.Examples(
55
+ examples=[
56
+ ["If we look at the plans for 2018, it is to introduce 650 new products, which is an absolute all- time high."],
57
+ ["We have been doing kind of an integrated campaign, so it's TV, online, we do the Google Ad Words - all those different elements together."],
58
+ ["So that turned out to be beneficial for us, and I think, we'll just see how the market and interest rates move over the course of the year,"]
59
+ ],
60
+ label="Examples (click to start detection)",
61
+ inputs=[text_in],
62
+ outputs=[score_out, html_out],
63
+ fn=classify,
64
+ run_on_click=True,
65
+ cache_examples=False
66
+ )
67
+ with gr.TabItem("πŸ“ Usage", id=1):
 
 
 
68
  gr.Markdown(
69
  """
70
  #### App usage
 
72
  It returns a confidence score that indicates the probability of the sentence containing a discussion on transformation activities. A value of 1 (0) signals a high confidence of the sentence being transformation-related (generic). A score in the range of [0.25; 0.75] implies that the model is rather undecided about the correct label.
73
  In addition, the app returns the tokenized version of the sentence, alongside word importances that are indicated by color codes. Those visuals illustrates the ability of the context-aware classifier to simultaneously pay attention to various parts in the input sentence to derive a final label.
74
  """
75
+ )
76
+ with gr.TabItem("πŸ“– About", id=2):
77
+ gr.Markdown(
78
+ """
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
  )
83
+
84
+
85
+ with gr.Accordion("πŸ“™ Citation", open=False):
86
+ citation_button = gr.Textbox(
87
+ value='Placeholder',
88
+ label='Copy to cite these results.',
89
+ show_copy_button=True
90
+ )
91
+
92
+
93
  compute_bt.click(classify, inputs=[text_in], outputs=[score_out, html_out])
94
 
95