Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
# file: deploy_demo.py
|
| 3 |
# time: 2021/10/10
|
| 4 |
-
# author: yangheng <
|
| 5 |
# github: https://github.com/yangheng95
|
| 6 |
# Copyright (C) 2021. All Rights Reserved.
|
| 7 |
|
|
@@ -10,7 +10,7 @@ import pandas as pd
|
|
| 10 |
|
| 11 |
from pyabsa import APCCheckpointManager
|
| 12 |
|
| 13 |
-
sentiment_classifier = APCCheckpointManager.get_sentiment_classifier(checkpoint='
|
| 14 |
auto_device=True # False means load model on CPU
|
| 15 |
)
|
| 16 |
|
|
@@ -18,6 +18,7 @@ sentiment_classifier = APCCheckpointManager.get_sentiment_classifier(checkpoint=
|
|
| 18 |
def inference(text):
|
| 19 |
result = sentiment_classifier.infer(text=text,
|
| 20 |
print_result=True,
|
|
|
|
| 21 |
clear_input_samples=True)
|
| 22 |
|
| 23 |
result = pd.DataFrame({
|
|
@@ -36,19 +37,16 @@ if __name__ == '__main__':
|
|
| 36 |
fn=inference,
|
| 37 |
inputs=["text"],
|
| 38 |
examples=[
|
| 39 |
-
['
|
| 40 |
-
['
|
|
|
|
| 41 |
['I have had my [ASP]computer[ASP] for 2 weeks already and it [ASP]works[ASP] perfectly . !sent! Positive, Positive'],
|
| 42 |
-
['
|
| 43 |
-
['Use [ASP] aspect [ASP] to wrap target aspects. And you can use "!sent!" to tell the model the true sentiment'],
|
| 44 |
['This demo is trained on the laptop and restaurant and other review datasets from [ASP]ABSADatasets[ASP] (https://github.com/yangheng95/ABSADatasets)'],
|
| 45 |
['To fit on your data, please train the model on your own data, see the [ASP]PyABSA[ASP] (https://github.com/yangheng95/PyABSA)'],
|
| 46 |
],
|
| 47 |
outputs="dataframe",
|
| 48 |
-
description='This demo is trained on the public and community shared datasets from ABSADatasets (https://github.com/yangheng95/ABSADatasets),'
|
| 49 |
-
' please feel free to share your data to improve this work. To fit on your data, please train our ATEPC models on your own data,'
|
| 50 |
-
' see the PyABSA (https://github.com/yangheng95/PyABSA/tree/release/demos/aspect_polarity_classification)',
|
| 51 |
title='Multilingual Aspect Sentiment Classification for Short Texts (powered by PyABSA)'
|
| 52 |
)
|
| 53 |
|
| 54 |
-
iface.launch()
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
# file: deploy_demo.py
|
| 3 |
# time: 2021/10/10
|
| 4 |
+
# author: yangheng <hy345@exeter.ac.uk>
|
| 5 |
# github: https://github.com/yangheng95
|
| 6 |
# Copyright (C) 2021. All Rights Reserved.
|
| 7 |
|
|
|
|
| 10 |
|
| 11 |
from pyabsa import APCCheckpointManager
|
| 12 |
|
| 13 |
+
sentiment_classifier = APCCheckpointManager.get_sentiment_classifier(checkpoint='multilingual',
|
| 14 |
auto_device=True # False means load model on CPU
|
| 15 |
)
|
| 16 |
|
|
|
|
| 18 |
def inference(text):
|
| 19 |
result = sentiment_classifier.infer(text=text,
|
| 20 |
print_result=True,
|
| 21 |
+
ignore_error=False,
|
| 22 |
clear_input_samples=True)
|
| 23 |
|
| 24 |
result = pd.DataFrame({
|
|
|
|
| 37 |
fn=inference,
|
| 38 |
inputs=["text"],
|
| 39 |
examples=[
|
| 40 |
+
['Strong build though which really adds to its [ASP]durability[ASP] .'], # !sent! Positive
|
| 41 |
+
['Strong [ASP]build[ASP] though which really adds to its durability . !sent! Positive'],
|
| 42 |
+
['The [ASP]battery life[ASP] is excellent - 6-7 hours without charging . !sent! Positive'],
|
| 43 |
['I have had my [ASP]computer[ASP] for 2 weeks already and it [ASP]works[ASP] perfectly . !sent! Positive, Positive'],
|
| 44 |
+
['And I may be the only one but I am really liking [ASP]Windows 8[ASP] . !sent! Positive'],
|
|
|
|
| 45 |
['This demo is trained on the laptop and restaurant and other review datasets from [ASP]ABSADatasets[ASP] (https://github.com/yangheng95/ABSADatasets)'],
|
| 46 |
['To fit on your data, please train the model on your own data, see the [ASP]PyABSA[ASP] (https://github.com/yangheng95/PyABSA)'],
|
| 47 |
],
|
| 48 |
outputs="dataframe",
|
|
|
|
|
|
|
|
|
|
| 49 |
title='Multilingual Aspect Sentiment Classification for Short Texts (powered by PyABSA)'
|
| 50 |
)
|
| 51 |
|
| 52 |
+
iface.launch(share=True)
|