tamatwi commited on
Commit
a7eaf04
·
verified ·
1 Parent(s): 78ffddf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import spaces
4
+
5
+ # 感情分析パイプラインの初期化
6
+ sentiment_analyzer = pipeline("sentiment-analysis")
7
+
8
+ # GPUを使用する関数の定義
9
+ @spaces.GPU
10
+ def analyze_sentiment(text):
11
+ result = sentiment_analyzer(text)[0]
12
+ return f"感情: {result['label']}, 確信度: {result['score']:.2f}"
13
+
14
+ # Gradioインターフェースの設定
15
+ iface = gr.Interface(
16
+ fn=analyze_sentiment,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="簡単な感情分析",
20
+ description="テキストを入力して、その感情を分析します。"
21
+ )
22
+
23
+ if __name__ == "__main__":
24
+ iface.launch()