Spaces:
Sleeping
Sleeping
dominguesm
commited on
Commit
·
7230c4d
1
Parent(s):
361fb8c
initial
Browse files- README.md +2 -2
- app.py +71 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
---
|
2 |
-
title: Positive Reframing
|
3 |
emoji: 🏃
|
4 |
colorFrom: blue
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.9.1
|
8 |
app_file: app.py
|
9 |
-
pinned:
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Positive Reframing PTBR
|
3 |
emoji: 🏃
|
4 |
colorFrom: blue
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.9.1
|
8 |
app_file: app.py
|
9 |
+
pinned: true
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from difflib import Differ
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
pipe = pipeline("summarization", "dominguesm/positive-reframing-ptbr")
|
7 |
+
|
8 |
+
|
9 |
+
def predict(text, operation):
|
10 |
+
try:
|
11 |
+
res = pipe(f"[{operation}]: {text}", max_length=1024)
|
12 |
+
except Exception as e:
|
13 |
+
return e
|
14 |
+
|
15 |
+
d = Differ()
|
16 |
+
return (
|
17 |
+
res[0]["summary_text"],
|
18 |
+
[
|
19 |
+
(token[2:], token[0] if token[0] != " " else None)
|
20 |
+
for token in d.compare(text, res[0]["summary_text"])
|
21 |
+
],
|
22 |
+
)
|
23 |
+
# return res[0]["summary_text"]
|
24 |
+
|
25 |
+
|
26 |
+
iface = gr.Interface(
|
27 |
+
title="Positive Reframing PT-BR",
|
28 |
+
description="This model is a PTT5 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-ptbr).",
|
29 |
+
fn=predict,
|
30 |
+
inputs=[
|
31 |
+
gr.Textbox(
|
32 |
+
lines=1,
|
33 |
+
placeholder=(
|
34 |
+
f"Pensar no meu futuro me faz querer viver numa ilha sozinha para sempre"
|
35 |
+
),
|
36 |
+
),
|
37 |
+
gr.Radio(
|
38 |
+
[
|
39 |
+
"growth",
|
40 |
+
"impermanence",
|
41 |
+
"neutralizing",
|
42 |
+
"optimism",
|
43 |
+
"self_affirmation",
|
44 |
+
"thankfulness",
|
45 |
+
]
|
46 |
+
),
|
47 |
+
],
|
48 |
+
outputs=[
|
49 |
+
gr.Textbox(label="Generated Text"),
|
50 |
+
gr.HighlightedText(
|
51 |
+
label="Diff",
|
52 |
+
combine_adjacent=True,
|
53 |
+
).style(color_map={"+": "green", "-": "red"}),
|
54 |
+
],
|
55 |
+
examples=[
|
56 |
+
[
|
57 |
+
"Tenho tanta coisa para fazer antes de sair da cidade por uma semana no domingo.",
|
58 |
+
"thankfulness",
|
59 |
+
],
|
60 |
+
[
|
61 |
+
"Aquele momento, você percebe que todo o trabalho duro foi para nada e você não tem controle sobre nada.",
|
62 |
+
"self_affirmation",
|
63 |
+
],
|
64 |
+
[
|
65 |
+
"Um daqueles dias em que você sente que precisa de um abraço de cinco minutos, um pacote de marshmallows e um amigo para conversar.",
|
66 |
+
"impermanence",
|
67 |
+
],
|
68 |
+
],
|
69 |
+
)
|
70 |
+
|
71 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
transformers[torch]
|