yangxinsci1993 commited on
Commit
f8b5b53
1 Parent(s): 57d278e

edit interface3

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -53,15 +53,15 @@ def reframe(input_text, strategy):
53
  # Input Control
54
  # The input text cannot be too short to ensure it has substantial content to be reframed. It also cannot be too long to ensure the text has a focused idea.
55
  if len(input_text) < CHAR_LENGTH_LOWER_BOUND or len(input_text) > CHAR_LENGTH_HIGHER_BOUND:
56
- return input_error_message(LENGTH_ERROR)
57
  # The input text cannot be too positive to ensure the text can be positively reframed.
58
  if TextBlob(input_text).sentiment.polarity > 0.2:
59
- return input_error_message(SENTIMENT_ERROR)
60
  # The input text cannot be offensive.
61
  sonar = Sonar()
62
  # sonar.ping(input_text) outputs a dictionary and the second score under the key classes is the confidence for the input text being offensive language
63
  if sonar.ping(input_text)['classes'][1]['confidence'] > OFFENSIVENESS_CONFIDENCE_THRESHOLD:
64
- return input_error_message(OFFENSIVE_ERROR)
65
 
66
  # Reframing
67
  # reframer pipeline outputs a list containing one dictionary where the value for 'summary_text' is the reframed text output
@@ -117,7 +117,7 @@ with gr.Blocks() as demo:
117
  gr.Markdown(
118
  '''
119
  # Positive Reframing
120
- Start inputing negative texts to see how you can see the same event from a positive angle.
121
  ''')
122
 
123
  # Input text to be reframed
@@ -126,7 +126,7 @@ with gr.Blocks() as demo:
126
  # Input strategy for the reframing
127
  gr.Markdown(
128
  '''
129
- Choose one of the six strategies to carry out reframing: \n
130
  **Growth Mindset:** Viewing a challenging event as an opportunity for the author specifically to grow or improve themselves. \n
131
  **Impermanence:** Saying bad things don’t last forever, will get better soon, and/or that others have experienced similar struggles. \n
132
  **Neutralizing:** Replacing a negative word with a neutral word. For example, “This was a terrible day” becomes “This was a long day.” \n
@@ -154,7 +154,7 @@ with gr.Blocks() as demo:
154
  # Default examples of text and strategy pairs for user to have a quick start
155
  gr.Markdown("## Examples")
156
  gr.Examples(
157
- [["I have a lot of homework to do today.", "self_affirmation"], ["This has been the longest and most stressful week of my life!", "optimism"], ["So stressed about the midterms next week.", "thankfulness"]],
158
  [text, strategy], best_output, show_reframe_change, cache_examples=False, run_on_click=False
159
  )
160
 
 
53
  # Input Control
54
  # The input text cannot be too short to ensure it has substantial content to be reframed. It also cannot be too long to ensure the text has a focused idea.
55
  if len(input_text) < CHAR_LENGTH_LOWER_BOUND or len(input_text) > CHAR_LENGTH_HIGHER_BOUND:
56
+ return input_text + input_error_message(LENGTH_ERROR)
57
  # The input text cannot be too positive to ensure the text can be positively reframed.
58
  if TextBlob(input_text).sentiment.polarity > 0.2:
59
+ return input_text + input_error_message(SENTIMENT_ERROR)
60
  # The input text cannot be offensive.
61
  sonar = Sonar()
62
  # sonar.ping(input_text) outputs a dictionary and the second score under the key classes is the confidence for the input text being offensive language
63
  if sonar.ping(input_text)['classes'][1]['confidence'] > OFFENSIVENESS_CONFIDENCE_THRESHOLD:
64
+ return input_text + input_error_message(OFFENSIVE_ERROR)
65
 
66
  # Reframing
67
  # reframer pipeline outputs a list containing one dictionary where the value for 'summary_text' is the reframed text output
 
117
  gr.Markdown(
118
  '''
119
  # Positive Reframing
120
+ **Start inputing negative texts to see how you can see the same event from a positive angle.**
121
  ''')
122
 
123
  # Input text to be reframed
 
126
  # Input strategy for the reframing
127
  gr.Markdown(
128
  '''
129
+ **Choose one of the six strategies to carry out reframing:** \n
130
  **Growth Mindset:** Viewing a challenging event as an opportunity for the author specifically to grow or improve themselves. \n
131
  **Impermanence:** Saying bad things don’t last forever, will get better soon, and/or that others have experienced similar struggles. \n
132
  **Neutralizing:** Replacing a negative word with a neutral word. For example, “This was a terrible day” becomes “This was a long day.” \n
 
154
  # Default examples of text and strategy pairs for user to have a quick start
155
  gr.Markdown("## Examples")
156
  gr.Examples(
157
+ [["I have a lot of homework to do today.", "self_affirmation"], ["So stressed about the midterm next week.", "optimism"], ["I failed my math quiz I am such a loser.", "growth"]],
158
  [text, strategy], best_output, show_reframe_change, cache_examples=False, run_on_click=False
159
  )
160