Spaces:
Build error
Build error
Update app.py
Browse filesChange to gradio Interface to show API.
app.py
CHANGED
|
@@ -111,57 +111,10 @@ def show_history(cache):
|
|
| 111 |
return gr.Textbox.update(value=history, visible=True)
|
| 112 |
|
| 113 |
|
| 114 |
-
# Build Gradio interface
|
| 115 |
-
with gr.Blocks() as demo:
|
| 116 |
-
# Instruction
|
| 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
|
| 124 |
-
text = gr.Textbox(label="Original Text")
|
| 125 |
-
|
| 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
|
| 133 |
-
**Optimism:** Focusing on things about the situation itself, in that moment, that are good (not just forecasting a better future). \n
|
| 134 |
-
**Self-affirmation:** Talking about what strengths the author already has, or the values they admire, like love, courage, perseverance, etc. \n
|
| 135 |
-
**Thankfulness:** Expressing thankfulness or gratitude with key words like appreciate, glad that, thankful for, good thing, etc.
|
| 136 |
-
''')
|
| 137 |
-
strategy = gr.Radio(
|
| 138 |
-
["thankfulness", "neutralizing", "optimism", "growth", "impermanence", "self_affirmation"], label="Strategy to use?"
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
# Trigger button for reframing
|
| 142 |
-
greet_btn = gr.Button("Reframe")
|
| 143 |
-
best_output = gr.HighlightedText(
|
| 144 |
-
label="Diff",
|
| 145 |
-
combine_adjacent=True,
|
| 146 |
-
).style(color_map={"+": "green", "-": "red"})
|
| 147 |
-
greet_btn.click(fn=show_reframe_change, inputs=[text, strategy], outputs=best_output)
|
| 148 |
-
|
| 149 |
-
# Trigger button for showing n best reframings
|
| 150 |
-
greet_btn = gr.Button("Show Best {n} Results".format(n=BEST_N))
|
| 151 |
-
n_best_output = gr.Textbox(interactive=False)
|
| 152 |
-
greet_btn.click(fn=show_n_best_decodes, inputs=[text, strategy], outputs=n_best_output)
|
| 153 |
-
|
| 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 |
-
|
| 161 |
-
# Link to paper and Github repo
|
| 162 |
-
gr.Markdown(
|
| 163 |
-
'''
|
| 164 |
-
For more details: You can read our [paper](https://arxiv.org/abs/2204.02952) or access our [code](https://github.com/SALT-NLP/positive-frames).
|
| 165 |
-
''')
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
demo.launch(show_api=True)
|
|
|
|
| 111 |
return gr.Textbox.update(value=history, visible=True)
|
| 112 |
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
demo = gr.Interface(
|
| 116 |
+
fn=show_reframe_change,
|
| 117 |
+
inputs=[gr.Textbox(lines=2, placeholder="Please input the sentence to be reframed.", label="Original Text"), gr.Radio(["thankfulness", "neutralizing", "optimism", "growth", "impermanence", "self_affirmation"], label="Strategy to use?")],
|
| 118 |
+
outputs=gr.HighlightedText(label="Diff",combine_adjacent=True,).style(color_map={"+": "green", "-": "red"}),
|
| 119 |
+
)
|
| 120 |
demo.launch(show_api=True)
|