JanviMl commited on
Commit
9302051
·
verified ·
1 Parent(s): 106e766

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -2,11 +2,13 @@
2
  import gradio as gr
3
  from classifier import classify_toxic_comment
4
 
5
- # Clear function for resetting the UI
6
  def clear_inputs():
 
 
 
 
7
  return "", 0, "", [], "", "", "", "", 0, "", "", "", "", "", "", "", ""
8
 
9
- # Custom CSS for styling
10
  custom_css = """
11
  /* General Styling */
12
  body {
@@ -121,9 +123,7 @@ h3 {
121
  }
122
  """
123
 
124
- # Main UI function
125
  with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
126
- # Header Section
127
  gr.Markdown(
128
  """
129
  # Toxic Comment Classifier
@@ -131,7 +131,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
131
  """
132
  )
133
 
134
- # Input Section
135
  with gr.Row():
136
  with gr.Column(scale=4, min_width=600):
137
  comment_input = gr.Textbox(
@@ -154,9 +153,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
154
  label="Try these examples:"
155
  )
156
 
157
- # Output Section
158
  with gr.Row():
159
- # Left Column: Original Comment Metrics
160
  with gr.Column(scale=1, min_width=400):
161
  gr.Markdown("### Original Comment Analysis")
162
  prediction_output = gr.Textbox(label="Prediction", placeholder="Prediction will appear here...")
@@ -172,7 +169,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
172
  bias_output = gr.Textbox(label="Bias Score", placeholder="Bias score will appear here...")
173
  threshold_display = gr.HTML()
174
 
175
- # Right Column: Paraphrased Output (if Toxic)
176
  with gr.Column(scale=1, min_width=400):
177
  with gr.Accordion("Paraphrased Output (if Toxic)", open=False):
178
  paraphrased_comment_output = gr.Textbox(label="Paraphrased Comment", placeholder="Paraphrased comment will appear here if the input is toxic...")
@@ -194,7 +190,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
194
  rouge_scores_output = gr.Textbox(label="ROUGE Scores", placeholder="ROUGE scores will appear here...")
195
  entailment_score_output = gr.Textbox(label="Entailment Score (Factual Consistency)", placeholder="Entailment score will appear here...")
196
 
197
- # History and Feedback Sections
198
  with gr.Row():
199
  with gr.Column(scale=1):
200
  with gr.Accordion("Prediction History", open=False):
@@ -265,7 +260,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
265
  )
266
  entailment_score_display = f"{entailment_score} (Scale: 0 to 1, higher indicates better consistency)" if entailment_score is not None else "N/A"
267
 
268
- # Add visual indicator to the prediction
269
  prediction_class = "toxic-indicator" if "Toxic" in prediction else "nontoxic-indicator"
270
  prediction_html = f"<span class='{prediction_class}' style='color: {color}; font-size: 20px; font-weight: bold;'>{prediction}</span>"
271
 
@@ -290,7 +284,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
290
  "Calculating... <span class='loading'>⏳</span>", "Calculating... <span class='loading'>⏳</span>",
291
  "Calculating... <span class='loading'>⏳</span>", "Calculating... <span class='loading'>⏳</span>",
292
  "Calculating... <span class='loading'>⏳</span>", "Calculating... <span class='loading'>⏳</span>"
293
- ), # Show loading state with animation
294
  inputs=[],
295
  outputs=[
296
  prediction_output, confidence_output, label_display, history_output, threshold_display, threshold_display,
 
2
  import gradio as gr
3
  from classifier import classify_toxic_comment
4
 
 
5
  def clear_inputs():
6
+ """
7
+ Reset all UI input and output fields to their default values.
8
+ Returns a tuple of empty or default values for all UI components.
9
+ """
10
  return "", 0, "", [], "", "", "", "", 0, "", "", "", "", "", "", "", ""
11
 
 
12
  custom_css = """
13
  /* General Styling */
14
  body {
 
123
  }
124
  """
125
 
 
126
  with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
 
127
  gr.Markdown(
128
  """
129
  # Toxic Comment Classifier
 
131
  """
132
  )
133
 
 
134
  with gr.Row():
135
  with gr.Column(scale=4, min_width=600):
136
  comment_input = gr.Textbox(
 
153
  label="Try these examples:"
154
  )
155
 
 
156
  with gr.Row():
 
157
  with gr.Column(scale=1, min_width=400):
158
  gr.Markdown("### Original Comment Analysis")
159
  prediction_output = gr.Textbox(label="Prediction", placeholder="Prediction will appear here...")
 
169
  bias_output = gr.Textbox(label="Bias Score", placeholder="Bias score will appear here...")
170
  threshold_display = gr.HTML()
171
 
 
172
  with gr.Column(scale=1, min_width=400):
173
  with gr.Accordion("Paraphrased Output (if Toxic)", open=False):
174
  paraphrased_comment_output = gr.Textbox(label="Paraphrased Comment", placeholder="Paraphrased comment will appear here if the input is toxic...")
 
190
  rouge_scores_output = gr.Textbox(label="ROUGE Scores", placeholder="ROUGE scores will appear here...")
191
  entailment_score_output = gr.Textbox(label="Entailment Score (Factual Consistency)", placeholder="Entailment score will appear here...")
192
 
 
193
  with gr.Row():
194
  with gr.Column(scale=1):
195
  with gr.Accordion("Prediction History", open=False):
 
260
  )
261
  entailment_score_display = f"{entailment_score} (Scale: 0 to 1, higher indicates better consistency)" if entailment_score is not None else "N/A"
262
 
 
263
  prediction_class = "toxic-indicator" if "Toxic" in prediction else "nontoxic-indicator"
264
  prediction_html = f"<span class='{prediction_class}' style='color: {color}; font-size: 20px; font-weight: bold;'>{prediction}</span>"
265
 
 
284
  "Calculating... <span class='loading'>⏳</span>", "Calculating... <span class='loading'>⏳</span>",
285
  "Calculating... <span class='loading'>⏳</span>", "Calculating... <span class='loading'>⏳</span>",
286
  "Calculating... <span class='loading'>⏳</span>", "Calculating... <span class='loading'>⏳</span>"
287
+ ),
288
  inputs=[],
289
  outputs=[
290
  prediction_output, confidence_output, label_display, history_output, threshold_display, threshold_display,