Upload 2 files
Browse files- app.py +37 -37
- requirements.txt +6 -4
app.py
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
def
|
11 |
-
aspects = [a.strip() for a in aspect_input.split(",") if a.strip()]
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
inference_source=[text],
|
16 |
-
aspect_sentiment_pair_list=
|
17 |
-
)
|
18 |
-
|
19 |
-
output = ""
|
20 |
-
for res in
|
21 |
-
for aspect, sentiment in res["aspect_sentiment_pair"]:
|
22 |
-
output += f"- **{aspect}** → **{sentiment}**\n"
|
23 |
-
return output
|
24 |
-
|
25 |
-
# Gradio 인터페이스
|
26 |
-
iface = gr.Interface(
|
27 |
-
fn=
|
28 |
-
inputs=[
|
29 |
-
gr.Textbox(label="입력
|
30 |
-
gr.Textbox(label="속성
|
31 |
-
],
|
32 |
-
outputs=gr.Markdown(label="감정 분석 결과"),
|
33 |
-
title="ABSA 감정 분석기 (DeBERTa v3)",
|
34 |
-
description="문장과
|
35 |
-
)
|
36 |
-
|
37 |
-
iface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pyabsa import AspectSentimentClassification as ASC
|
3 |
+
|
4 |
+
# 모델 로드
|
5 |
+
aspect_extractor = ASC.SentimentClassifier(
|
6 |
+
checkpoint='yangheng/deberta-v3-base-absa-v1.1'
|
7 |
+
)
|
8 |
+
|
9 |
+
# 분석 함수
|
10 |
+
def absa(text, aspect_input):
|
11 |
+
aspects = [a.strip() for a in aspect_input.split(",") if a.strip()]
|
12 |
+
pairs = [[text, aspect] for aspect in aspects]
|
13 |
+
|
14 |
+
results = aspect_extractor.infer(
|
15 |
+
inference_source=[text],
|
16 |
+
aspect_sentiment_pair_list=pairs
|
17 |
+
)
|
18 |
+
|
19 |
+
output = ""
|
20 |
+
for res in results:
|
21 |
+
for aspect, sentiment in res["aspect_sentiment_pair"]:
|
22 |
+
output += f"- **{aspect}** → **{sentiment}**\n"
|
23 |
+
return output
|
24 |
+
|
25 |
+
# Gradio 인터페이스 생성
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=absa,
|
28 |
+
inputs=[
|
29 |
+
gr.Textbox(label="문장 입력", placeholder="예: The battery is good, but the screen is dim."),
|
30 |
+
gr.Textbox(label="속성 입력 (쉼표로 구분)", placeholder="예: battery, screen")
|
31 |
+
],
|
32 |
+
outputs=gr.Markdown(label="속성별 감정 분석 결과"),
|
33 |
+
title="ABSA 감정 분석기 (DeBERTa v3)",
|
34 |
+
description="문장과 속성을 입력하면 속성별 감정을 추출합니다. 모델: yangheng/deberta-v3-base-absa-v1.1"
|
35 |
+
)
|
36 |
+
|
37 |
+
iface.launch()
|
requirements.txt
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
-
gradio
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
git+https://github.com/yangheng95/ABSAgym
|
3 |
+
transformers==4.28.1
|
4 |
+
protobuf==4.25.2
|
5 |
+
findfile
|
6 |
+
pytorch_lightning==1.9.5
|