Spaces:
Sleeping
Sleeping
simonschoe
commited on
Commit
β’
c75d824
1
Parent(s):
27b2a2c
app redesign
Browse files
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:
|
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
|
41 |
## Detect Transformation-Related Sentences in Quarterly Earnings Calls
|
42 |
"""
|
43 |
)
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
with gr.Row():
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
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 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
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: </b><span style="display: inline-block; width: 10px; height: 10px; border: 1px solid; background-color: hsl(0, 75%, 60%)"></span> No Transformation Talk <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 |
|