Rework the layout for better usability and readability
Browse files
app.py
CHANGED
@@ -31,8 +31,7 @@ classifier = pipeline(
|
|
31 |
top_k=None, # Returns all scores for all labels, not just the one with the highest score
|
32 |
truncation=True, # Truncates the input text if it exceeds the maximum length
|
33 |
max_length=512, # Defines the maximum length of the input text (512 for BERT. Explicitly set here)
|
34 |
-
torch_dtype=torch_d_type
|
35 |
-
# Sets the torch dtype to 16-bit half-precision floating-point format if CUDA is available, otherwise sets it to 32-bit single-precision floating-point format
|
36 |
)
|
37 |
|
38 |
|
@@ -62,20 +61,16 @@ examples = [
|
|
62 |
["Review: Great game, but the community is toxic., Playtime: 50, Voted Up: True, Upvotes: 1, Votes Funny: 0"]
|
63 |
]
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
)
|
71 |
|
|
|
72 |
labeling_criteria = (
|
73 |
"""
|
74 |
-
<br>
|
75 |
-
<hr style="width: 75%; margin-left: auto; margin-right: auto;">
|
76 |
-
<b><u>Labeling Criteria:</u></b>
|
77 |
-
<br>
|
78 |
-
<br>
|
79 |
<ul>
|
80 |
<li>
|
81 |
<b><span style="color:green;">Constructive</span></b>:
|
@@ -91,51 +86,72 @@ labeling_criteria = (
|
|
91 |
"""
|
92 |
)
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# Main Gradio Interface using Gradio Blocks
|
95 |
# Docs: https://www.gradio.app/docs/gradio/blocks
|
96 |
with gr.Blocks() as steam_reviews_classifier_block:
|
97 |
-
gr.
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
#
|
103 |
-
with gr.
|
104 |
-
#
|
105 |
-
with gr.Column():
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
show_copy_button=False,
|
112 |
-
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
interactive=False,
|
130 |
-
show_copy_button=False,
|
131 |
-
# info="Textual representation of the Constructiveness Prediction"
|
132 |
-
)
|
133 |
-
|
134 |
-
# Submit Button
|
135 |
-
submit_button = gr.Button(value="Submit")
|
136 |
-
|
137 |
-
# Labeling Criteria
|
138 |
-
gr.Markdown(labeling_criteria)
|
139 |
|
140 |
# Function to run when the Submit Button is clicked (Passes the input text to the classifier and displays the output text)
|
141 |
def on_submit_click(input_text):
|
|
|
31 |
top_k=None, # Returns all scores for all labels, not just the one with the highest score
|
32 |
truncation=True, # Truncates the input text if it exceeds the maximum length
|
33 |
max_length=512, # Defines the maximum length of the input text (512 for BERT. Explicitly set here)
|
34 |
+
torch_dtype=torch_d_type # Sets the torch dtype to 16-bit half-precision floating-point format if CUDA is available, otherwise sets it to 32-bit single-precision floating-point format
|
|
|
35 |
)
|
36 |
|
37 |
|
|
|
61 |
["Review: Great game, but the community is toxic., Playtime: 50, Voted Up: True, Upvotes: 1, Votes Funny: 0"]
|
62 |
]
|
63 |
|
64 |
+
# Information Description about the Steam Review Format
|
65 |
+
# info_description = (
|
66 |
+
# """
|
67 |
+
# Format your input as follows for the best results: ***Review**: {review_text}, **Playtime**: {author_playtime_at_review}, **Voted Up**: {voted_up}, **Upvotes**: {upvotes}, **Votes Funny**: {votes_funny}.*
|
68 |
+
# """
|
69 |
+
# )
|
70 |
|
71 |
+
# Labeling Criteria Information Markdown
|
72 |
labeling_criteria = (
|
73 |
"""
|
|
|
|
|
|
|
|
|
|
|
74 |
<ul>
|
75 |
<li>
|
76 |
<b><span style="color:green;">Constructive</span></b>:
|
|
|
86 |
"""
|
87 |
)
|
88 |
|
89 |
+
# Custom CSS to create a card-like design for the Gradio Interface
|
90 |
+
custom_css = """
|
91 |
+
<style>
|
92 |
+
.card {
|
93 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
94 |
+
padding: 16px;
|
95 |
+
border-radius: 12px;
|
96 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
97 |
+
background-color: transparent;
|
98 |
+
margin-bottom: 16px;
|
99 |
+
}
|
100 |
+
</style>
|
101 |
+
"""
|
102 |
+
|
103 |
# Main Gradio Interface using Gradio Blocks
|
104 |
# Docs: https://www.gradio.app/docs/gradio/blocks
|
105 |
with gr.Blocks() as steam_reviews_classifier_block:
|
106 |
+
with gr.Column(elem_classes=["card"]):
|
107 |
+
gr.Markdown("## Steam Review Constructiveness Classifier")
|
108 |
+
# gr.Markdown(info_description)
|
109 |
+
|
110 |
+
gr.HTML(custom_css)
|
111 |
+
# Main Column
|
112 |
+
with gr.Column():
|
113 |
+
# Card Column to create a card-like Design for the Main Functionality Components
|
114 |
+
with gr.Column(elem_classes=["card"]):
|
115 |
+
# Upper Row (Input Textbox, Constructive Label, Not Constructive Label)
|
116 |
+
with gr.Row(equal_height=True):
|
117 |
+
# Input Textbox Column
|
118 |
+
with gr.Column():
|
119 |
+
input_textbox = gr.Textbox(
|
120 |
+
lines=8,
|
121 |
+
label="Steam Review",
|
122 |
+
# info="Input Steam Review here",
|
123 |
+
placeholder="Review: I think this is a great game but it still has some room for improvement., Playtime: 12, Voted Up: True, Upvotes: 1, Votes Funny: 0",
|
124 |
+
show_copy_button=False,
|
125 |
+
value="Review: I think this is a great game but it still has some room for improvement., Playtime: 12, Voted Up: True, Upvotes: 1, Votes Funny: 0"
|
126 |
+
)
|
127 |
+
|
128 |
+
# Constructive and Not Constructive Labels Column
|
129 |
+
with gr.Column():
|
130 |
+
constructive_label = gr.Label(label="Constructive")
|
131 |
+
not_constructive_label = gr.Label(label="Not Constructive")
|
132 |
+
|
133 |
+
# Output Textbox which shows the textual representation of the Constructiveness Prediction
|
134 |
+
output_textbox = gr.Textbox(
|
135 |
+
label="Constructiveness Prediction",
|
136 |
+
interactive=False,
|
137 |
show_copy_button=False,
|
138 |
+
# info="Textual representation of the Constructiveness Prediction"
|
139 |
)
|
140 |
|
141 |
+
gr.Markdown("<br>")
|
142 |
+
|
143 |
+
# Examples Component
|
144 |
+
example_component = gr.Examples(
|
145 |
+
examples=examples,
|
146 |
+
inputs=input_textbox
|
147 |
+
)
|
148 |
+
|
149 |
+
# Submit Button
|
150 |
+
submit_button = gr.Button(value="Submit")
|
151 |
+
|
152 |
+
# Collapsable Labeling Criteria Info Accordion
|
153 |
+
with gr.Accordion(label="See Labeling Criteria", open=False):
|
154 |
+
gr.Markdown(labeling_criteria)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
# Function to run when the Submit Button is clicked (Passes the input text to the classifier and displays the output text)
|
157 |
def on_submit_click(input_text):
|