Spaces:
Sleeping
Sleeping
kietnt0603
commited on
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
3 |
+
|
4 |
+
classifier = pipeline("text-classification", model="kietnt0603/vi-coqe-stage1")
|
5 |
+
generator = pipeline(model="kietnt0603/vi-coqe-stage2")
|
6 |
+
|
7 |
+
def filter(example):
|
8 |
+
classifier_result = classifier(example)[0]['label']
|
9 |
+
if classifier_result == "LABEL_0":
|
10 |
+
return 0
|
11 |
+
else:
|
12 |
+
return 1
|
13 |
+
|
14 |
+
def extract_quin(example):
|
15 |
+
instruction = "Hãy rút trích bộ năm thông tin gồm chủ thể, đối tượng, khía cạnh, vị từ so sánh, loại so sánh trong câu: "
|
16 |
+
if filter(example):
|
17 |
+
return generator(instruction + example, max_new_tokens=128)[0]['generated_text']
|
18 |
+
else:
|
19 |
+
return "No quintuple found."
|
20 |
+
|
21 |
+
# Create title and description for our task
|
22 |
+
title = "COQE Demo"
|
23 |
+
description = "Welcome to the COQE Demo! Given a sentence, it identifies the aspects (entities or attributes) being talked about, the opinions or describing terms related to these aspects, and the sentiment polarity (positive, negative, or neutral) of these opinions. This tool can be particularly useful for analyzing customer reviews, social media posts, and other forms of user-generated content. Simply enter your text in the box below and click ‘Submit’ to see the extracted triplets."
|
24 |
+
# Create the Gradio interface
|
25 |
+
iface = gr.Interface(fn=extract_quin,
|
26 |
+
inputs="textbox",
|
27 |
+
outputs="textbox",
|
28 |
+
title=title,
|
29 |
+
# description=description,
|
30 |
+
# article=article)
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the interface
|
34 |
+
iface.launch()
|