Spaces:
Runtime error
Runtime error
File size: 4,007 Bytes
b717311 fdd305a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
from difflib import Differ
import gradio as gr
from transformers import pipeline
pipe = pipeline("summarization", "dominguesm/positive-reframing-en")
def predict(text, operation):
try:
res = pipe(f"[{operation}]: {text}", max_length=124)
except Exception as e:
return e
d = Differ()
return (
res[0]["summary_text"],
[
(token[2:], token[0] if token[0] != " " else None)
for token in d.compare(text, res[0]["summary_text"])
],
)
# return res[0]["summary_text"]
iface = gr.Interface(
title="Positive Reframing EN",
description="This model is a T5 adjusted to the sentiment transfer task, where the objective is to reverse the sentiment polarity of a text without contradicting the original meaning. Positive reframing induces a complementary positive viewpoint (e.g. glass-half-full) escaping negative patterns. More info [here](https://huggingface.co/dominguesm/positive-reframing-en).",
fn=predict,
inputs=[
gr.Textbox(
lines=1,
placeholder=(
f"Pensar no meu futuro me faz querer viver numa ilha sozinha para sempre"
),
),
gr.Radio(
[
"growth",
"impermanence",
"neutralizing",
"optimism",
"self_affirmation",
"thankfulness",
]
),
],
outputs=[
gr.Textbox(label="Generated Text"),
gr.HighlightedText(
label="Diff",
combine_adjacent=True,
).style(color_map={"+": "green", "-": "red"}),
],
examples=[
[
"You know I really don't care about the power struggle between the papacy and secular authority in the medieval ages. stupid",
"growth",
],
[
"thinking about my future makes me want to go live on a island alone forever. annoyed",
"optimism",
],
[
"Who would have ever guessed that it would be so freaking hard to get three different grades from two different schools together.",
"thankfulness",
],
],
)
iface.launch()
import streamlit as st
# Dataset
examples = [
[
"The power struggle between the papacy and secular authority in the medieval ages is as unimportant to me as a drop of water in the ocean. (simile)",
"growth",
],
[
"Contemplating my future feels like being engulfed by the urge to escape to a secluded island, forever. (metaphor)",
"optimism",
],
[
"Who would have thought that uniting three different grades from two different schools would be as tough as nailing jelly to a wall? (simile)",
"thankfulness",
],
[
"Her laughter was like the tinkling of silver bells, filling the room with joy. (simile)",
"happiness",
],
[
"The thunder roared and boomed, striking fear in the hearts of those who heard it. (onomatopoeia)",
"courage",
],
]
language_features = [
"Metaphor",
"Simile",
"Onomatopoeia",
"Alliteration",
"Assonance",
"Hyperbole",
"Personification",
"Oxymoron",
"Paradox",
"Pun",
"Irony",
"Sarcasm",
"Allusion",
"Imagery",
"Symbolism",
"Anaphora",
"Epistrophe",
"Parallelism",
"Euphemism",
"Synecdoche",
]
# Streamlit app
st.title("Language Feature Emoji Reference")
# Table of buttons
table_data = [language_features[i:i + 3] for i in range(0, len(language_features), 3)]
for row in table_data:
row_buttons = st.beta_columns(len(row))
for i, feature in enumerate(row):
if row_buttons[i].button(feature):
for example in examples:
if feature.lower() in example[0]:
st.write(f"**{feature}:** {example[0]}")
st.write(f"**Emoji:** {example[1]}")
st.write("---")
|