Spaces:
Sleeping
Sleeping
add checkbox
Browse files
app.py
CHANGED
|
@@ -3,12 +3,27 @@ from transformers import pipeline
|
|
| 3 |
import utils
|
| 4 |
|
| 5 |
st.title("Indo LEGO-ABSA")
|
| 6 |
-
example_text = "EXAMPLE: Pizza nya enak sekali
|
| 7 |
text = st.text_area("Enter your text here", "", placeholder=example_text)
|
|
|
|
|
|
|
|
|
|
| 8 |
pipe = pipeline(model="rdyzakya/IndoLEGO-ABSA")
|
|
|
|
|
|
|
| 9 |
|
| 10 |
if text:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import utils
|
| 4 |
|
| 5 |
st.title("Indo LEGO-ABSA")
|
| 6 |
+
example_text = "EXAMPLE: Pizza nya enak sekali"
|
| 7 |
text = st.text_area("Enter your text here", "", placeholder=example_text)
|
| 8 |
+
aspect = st.checkbox("Aspect", value=True)
|
| 9 |
+
opinion = st.checkbox("Opinion")
|
| 10 |
+
sentiment = st.checkbox("Sentiment")
|
| 11 |
pipe = pipeline(model="rdyzakya/IndoLEGO-ABSA")
|
| 12 |
+
prompt = ""
|
| 13 |
+
se_order = ""
|
| 14 |
|
| 15 |
if text:
|
| 16 |
+
if aspect:
|
| 17 |
+
se_order += 'a'
|
| 18 |
+
if opinion:
|
| 19 |
+
se_order += 'o'
|
| 20 |
+
if sentiment:
|
| 21 |
+
se_order += 's'
|
| 22 |
+
se_order = set(se_order)
|
| 23 |
+
if not se_order.issubset("acos"):
|
| 24 |
+
st.json([])
|
| 25 |
+
else:
|
| 26 |
+
inputs = utils.add_prompt(text, se_order)
|
| 27 |
+
out = pipe(inputs)
|
| 28 |
+
result = utils.catch_answer(out[0]["generated_text"], str(se_order))
|
| 29 |
+
st.json(result)
|
utils.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
import re
|
| 2 |
import constant
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
return se_order
|
| 11 |
|
| 12 |
def catch_answer(out, se_order):
|
| 13 |
if out == constant.NO_TARGET:
|
|
@@ -22,10 +21,4 @@ def catch_answer(out, se_order):
|
|
| 22 |
for i in range(len(result)):
|
| 23 |
for k, v in result[i].items():
|
| 24 |
result[i][k] = v.strip()
|
| 25 |
-
return result
|
| 26 |
-
|
| 27 |
-
if __name__ == "__main__":
|
| 28 |
-
print(catch_answer(
|
| 29 |
-
'<extra_id_0> Pizza nya <extra_id_1> enak sekali <extra_id_2> positive',
|
| 30 |
-
'aos'
|
| 31 |
-
))
|
|
|
|
| 1 |
import re
|
| 2 |
import constant
|
| 3 |
+
def add_prompt(text, se_order="aos"):
|
| 4 |
+
prompt = []
|
| 5 |
+
for counter, se in enumerate(se_order):
|
| 6 |
+
prompt.append(constant.SENTIMENT_ELEMENT[se] + " : " + f"<extra_id_{counter}>")
|
| 7 |
+
prompt = " ,".join(prompt)
|
| 8 |
+
result = text + "| " + prompt
|
| 9 |
+
return result
|
|
|
|
| 10 |
|
| 11 |
def catch_answer(out, se_order):
|
| 12 |
if out == constant.NO_TARGET:
|
|
|
|
| 21 |
for i in range(len(result)):
|
| 22 |
for k, v in result[i].items():
|
| 23 |
result[i][k] = v.strip()
|
| 24 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|