Spaces:
Sleeping
Sleeping
Chang Che Wei
commited on
Commit
·
a00fca0
1
Parent(s):
a56bc8b
initial gradio demo
Browse files- gradio_app.py +0 -29
gradio_app.py
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
-
import gradio as gr
|
3 |
-
import os
|
4 |
-
|
5 |
-
# 1. 建立情緒分析管線
|
6 |
-
sent_cls = pipeline(
|
7 |
-
task="sentiment-analysis",
|
8 |
-
model="uer/roberta-base-finetuned-jd-binary-chinese" # 雙分類
|
9 |
-
)
|
10 |
-
|
11 |
-
# 2. 推論函式
|
12 |
-
def classify(text: str):
|
13 |
-
if not text.strip():
|
14 |
-
return {"error": "請輸入文字"}
|
15 |
-
res = sent_cls(text)[0]
|
16 |
-
return {"label": res["label"], "score": round(res["score"], 4)}
|
17 |
-
|
18 |
-
# 3. Gradio 介面
|
19 |
-
demo = gr.Interface(
|
20 |
-
fn=classify,
|
21 |
-
inputs=gr.Textbox(lines=4, placeholder="輸入評論…"),
|
22 |
-
outputs="json",
|
23 |
-
title="中文情緒分析 Demo",
|
24 |
-
description="RoBERTa 中文二分類情緒分析(positive/negative)"
|
25 |
-
)
|
26 |
-
|
27 |
-
if __name__ == "__main__":
|
28 |
-
# localhost:7860 預覽
|
29 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|