COQE-Demo / app.py
kietnt0603's picture
Upload app.py
98f78f7 verified
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
classifier = pipeline("text-classification", model="kietnt0603/vi-coqe-stage1")
generator = pipeline(model="kietnt0603/vi-coqe-stage2")
def filter(example):
classifier_result = classifier(example)[0]['label']
if classifier_result == "LABEL_0":
return 0
else:
return 1
def extract_quin(example):
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: "
if filter(example):
return generator(instruction + example, max_new_tokens=128)[0]['generated_text']
else:
return "No quintuple found."
# Create title and description for our task
title = "COQE Demo"
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."
# Create the Gradio interface
iface = gr.Interface(fn=extract_quin,
inputs="textbox",
outputs="textbox",
title=title,
# description=description,
# article=article)
)
# Launch the interface
iface.launch()