yjpark75 commited on
Commit
1bbc69a
·
verified ·
1 Parent(s): 127cd21

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +37 -37
  2. requirements.txt +6 -4
app.py CHANGED
@@ -1,37 +1,37 @@
1
- # app.py
2
- import gradio as gr
3
- from pyabsa import ATEPCCheckpointManager
4
-
5
- # 모델 로딩 (최초 실행 시 약간 시간 소요)
6
- aspect_extractor = ATEPCCheckpointManager.get_aspect_sentiment_extractor(
7
- checkpoint='yangheng/deberta-v3-base-absa-v1.1'
8
- )
9
-
10
- def analyze_aspects(text, aspect_input):
11
- aspects = [a.strip() for a in aspect_input.split(",") if a.strip()]
12
- pair_list = [[text, aspect] for aspect in aspects]
13
-
14
- result = aspect_extractor.extract_aspect_sentiment_inference(
15
- inference_source=[text],
16
- aspect_sentiment_pair_list=pair_list
17
- )
18
-
19
- output = ""
20
- for res in result:
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=analyze_aspects,
28
- inputs=[
29
- gr.Textbox(label="입력 문장", placeholder="예: The food was great but the service was slow."),
30
- gr.Textbox(label="속성 목록 (쉼표로 구분)", placeholder="예: food, service")
31
- ],
32
- outputs=gr.Markdown(label="감정 분석 결과"),
33
- title="ABSA 감정 분석기 (DeBERTa v3)",
34
- description="문장과 속성(aspect)를 입력하면 속성별 감정을 추출합니다. 모델: yangheng/deberta-v3-base-absa-v1.1"
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
- pyabsa
3
- findfile
4
- pytorch_lightning
 
 
 
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