Spaces:
Runtime error
Runtime error
Commit
·
ca77d3c
1
Parent(s):
eecb5cf
initial
Browse files- README.md +2 -2
- app.py +72 -0
- requirements.txt +0 -0
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
---
|
2 |
-
title: Positive Reframing
|
3 |
emoji: 💻
|
4 |
colorFrom: purple
|
5 |
colorTo: gray
|
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 EN
|
3 |
emoji: 💻
|
4 |
colorFrom: purple
|
5 |
colorTo: gray
|
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,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from difflib import Differ
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
pipe = pipeline("summarization", "dominguesm/positive-reframing-en")
|
7 |
+
|
8 |
+
|
9 |
+
def predict(text, operation):
|
10 |
+
|
11 |
+
try:
|
12 |
+
res = pipe(f"[{operation}]: {text}", max_length=1024)
|
13 |
+
except Exception as e:
|
14 |
+
return e
|
15 |
+
|
16 |
+
d = Differ()
|
17 |
+
return (
|
18 |
+
res[0]["summary_text"],
|
19 |
+
[
|
20 |
+
(token[2:], token[0] if token[0] != " " else None)
|
21 |
+
for token in d.compare(text, res[0]["summary_text"])
|
22 |
+
],
|
23 |
+
)
|
24 |
+
# return res[0]["summary_text"]
|
25 |
+
|
26 |
+
|
27 |
+
iface = gr.Interface(
|
28 |
+
title="Positive Reframing EN",
|
29 |
+
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).",
|
30 |
+
fn=predict,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(
|
33 |
+
lines=1,
|
34 |
+
placeholder=(
|
35 |
+
f"Pensar no meu futuro me faz querer viver numa ilha sozinha para sempre"
|
36 |
+
),
|
37 |
+
),
|
38 |
+
gr.Radio(
|
39 |
+
[
|
40 |
+
"growth",
|
41 |
+
"impermanence",
|
42 |
+
"neutralizing",
|
43 |
+
"optimism",
|
44 |
+
"self_affirmation",
|
45 |
+
"thankfulness",
|
46 |
+
]
|
47 |
+
),
|
48 |
+
],
|
49 |
+
outputs=[
|
50 |
+
gr.Textbox(label="Generated Text"),
|
51 |
+
gr.HighlightedText(
|
52 |
+
label="Diff",
|
53 |
+
combine_adjacent=True,
|
54 |
+
).style(color_map={"+": "green", "-": "red"}),
|
55 |
+
],
|
56 |
+
examples=[
|
57 |
+
[
|
58 |
+
"You know I really don't care about the power struggle between the papacy and secular authority in the medieval ages. stupid",
|
59 |
+
"growth",
|
60 |
+
],
|
61 |
+
[
|
62 |
+
"thinking about my future makes me want to go live on a island alone forever. annoyed",
|
63 |
+
"optimism",
|
64 |
+
],
|
65 |
+
[
|
66 |
+
"Who would have ever guessed that it would be so freaking hard to get three different grades from two different schools together.",
|
67 |
+
"thankfulness",
|
68 |
+
],
|
69 |
+
],
|
70 |
+
)
|
71 |
+
|
72 |
+
iface.launch()
|
requirements.txt
ADDED
File without changes
|