Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# file: deploy_demo.py
|
| 3 |
+
# time: 2021/10/10
|
| 4 |
+
# author: yangheng <yangheng@m.scnu.edu.cn>
|
| 5 |
+
# github: https://github.com/yangheng95
|
| 6 |
+
# Copyright (C) 2021. All Rights Reserved.
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import pandas as pd
|
| 10 |
+
|
| 11 |
+
from pyabsa import ATEPCCheckpointManager
|
| 12 |
+
|
| 13 |
+
aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='multilingual')
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def inference(text):
|
| 17 |
+
result = aspect_extractor.extract_aspect(inference_source=[text],
|
| 18 |
+
pred_sentiment=True)
|
| 19 |
+
|
| 20 |
+
result = pd.DataFrame({
|
| 21 |
+
'aspect': result[0]['aspect'],
|
| 22 |
+
'sentiment': result[0]['sentiment'],
|
| 23 |
+
'position': result[0]['position']
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
return result
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
if __name__ == '__main__':
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=inference,
|
| 32 |
+
inputs=["text"],
|
| 33 |
+
examples=[
|
| 34 |
+
['Even though it is running Snow Leopard, 2.4 GHz C2D is a bit of an antiquated CPU and thus the occasional spinning '
|
| 35 |
+
'wheel would appear when running Office Mac applications such as Word or Excel .'],
|
| 36 |
+
['从这门课程的内容丰富程度还有老师的授课及讨论区的答疑上来说,我都是很喜欢的。但是吧,我觉得每个章的内容太多了,三个学分的量就分在了上个章节三次小测'],
|
| 37 |
+
['Als je geen steak liefhebber bent is er een visalternatief, eend en lam aan aanvaardbare prijzen.'],
|
| 38 |
+
['سأوصي بالتأكيد بموقع المدينة القديمة إلا إنه عليك الحذر من الأسعار السياحية الأكثر ارتفاعاً'],
|
| 39 |
+
['Nous avons bien aimé l\'ambiance, sur la promenade principale de Narbonne-Plage, et la qualité du service.'],
|
| 40 |
+
['По поводу интерьера: место спокойное, шумных компаний нет (не было, по крайней мере, в момент нашего посещения), очень приятная и уютная атмосфера, все в лучших традициях.'],
|
| 41 |
+
['la calidad del producto, el servicio, el entorno todo fue excelente'],
|
| 42 |
+
['Yemekler iyi hos, lezzetler iyi ama heyecan verici bi taraflari yok, iyi bir baligi iyi bir sekilde izgara yapmak artik atla deve bi olay degil.'],
|
| 43 |
+
['このレストランのサービスはまあまあで,待ち時間は長かったが,料理はまずまずのものだった'],
|
| 44 |
+
['이 식당의 서비스는 아주 평범했는데, 대기 시간이 오래 걸렸지만, 요리는 그런대로 만족스러웠다'],
|
| 45 |
+
['Die wartezeit war recht mittelmäßig, aber das Essen war befriedigend'],
|
| 46 |
+
['O serviço é médio, o tempo de espera é longo, mas os pratos são razoavelmente satisfatórios'],
|
| 47 |
+
['Dịch vụ của nhà hàng này rất trung bình và thời gian chờ đợi rất dài, nhưng món ăn thì khá là thỏa mãn'],
|
| 48 |
+
['Pelayanan di restoran biasa dan penantian yang lama, tetapi hasilnya cukup memuaskan'],
|
| 49 |
+
['ร้านนี้ มีบริการทั่วไปรอเป็นเวลานาน แต่อาหารก็น่าพอใจ'],
|
| 50 |
+
['This demo is trained on the public and community shared datasets from ABSADatasets (https://github.com/yangheng95/ABSADatasets),'
|
| 51 |
+
' please feel free to share your data to improve this work'],
|
| 52 |
+
['To fit on your data, please train our ATEPC models on your own data, see the PyABSA (https://github.com/yangheng95/PyABSA/tree/release/demos/aspect_term_extraction)'],
|
| 53 |
+
],
|
| 54 |
+
outputs="dataframe",
|
| 55 |
+
title='Multilingual Aspect Term Extraction for Short Texts (powered by PyABSA)'
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
iface.launch()
|