Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ import os
|
|
5 |
import shutil
|
6 |
from process import AudioProcessor
|
7 |
from transcription import TranscriptionMaker
|
|
|
|
|
8 |
|
9 |
process=AudioProcessor()
|
10 |
transcription = TranscriptionMaker()
|
@@ -12,6 +14,12 @@ app = Flask(__name__)
|
|
12 |
|
13 |
users = []
|
14 |
segments_dir = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# トップページ(テンプレート: index.html)
|
17 |
@app.route('/')
|
@@ -42,8 +50,41 @@ def confirm():
|
|
42 |
@app.route('/transcription',methods =['GET','POST'])
|
43 |
def transcription():
|
44 |
global segments_dir
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# 音声アップロード&解析エンドポイント
|
49 |
@app.route('/upload_audio', methods=['POST'])
|
|
|
5 |
import shutil
|
6 |
from process import AudioProcessor
|
7 |
from transcription import TranscriptionMaker
|
8 |
+
from analyze import TextAnalyzer
|
9 |
+
import json
|
10 |
|
11 |
process=AudioProcessor()
|
12 |
transcription = TranscriptionMaker()
|
|
|
14 |
|
15 |
users = []
|
16 |
segments_dir = ""
|
17 |
+
transcription_text=""
|
18 |
+
harassment_keywords = [
|
19 |
+
"バカ", "馬鹿", "アホ", "死ね", "クソ", "うざい",
|
20 |
+
"きもい", "キモい", "ブス", "デブ", "ハゲ",
|
21 |
+
"セクハラ", "パワハラ", "モラハラ"
|
22 |
+
]
|
23 |
|
24 |
# トップページ(テンプレート: index.html)
|
25 |
@app.route('/')
|
|
|
50 |
@app.route('/transcription',methods =['GET','POST'])
|
51 |
def transcription():
|
52 |
global segments_dir
|
53 |
+
global transcription_text
|
54 |
+
transcription_text = transcription.create_transcription(segments_dir)
|
55 |
+
return jsonify({'transcription': transcription_text}),200
|
56 |
+
|
57 |
+
# AI分析エンドポイント
|
58 |
+
@app.route('/analyze',methods =['GET','POST'])
|
59 |
+
def analyze():
|
60 |
+
global transcription_text
|
61 |
+
analyzer = TextAnalyzer(transcription_text, harassment_keywords)
|
62 |
+
api_key = os.environ.get("DEEPSEEK")
|
63 |
+
if api_key is None:
|
64 |
+
raise ValueError("DEEPSEEK_API_KEY が設定されていません。")
|
65 |
+
|
66 |
+
results = analyzer.analyze(api_key=api_key)
|
67 |
+
|
68 |
+
print(json.dumps(results, ensure_ascii=False, indent=2))
|
69 |
+
|
70 |
+
if "deepseek_analysis" in results and results["deepseek_analysis"]:
|
71 |
+
deepseek_data = results["deepseek_analysis"]
|
72 |
+
conversation_level = deepseek_data.get("conversationLevel")
|
73 |
+
harassment_present = deepseek_data.get("harassmentPresent")
|
74 |
+
harassment_type = deepseek_data.get("harassmentType")
|
75 |
+
repetition = deepseek_data.get("repetition")
|
76 |
+
pleasantConversation = deepseek_data.get("pleasantConversation")
|
77 |
+
blameOrHarassment = deepseek_data.get("blameOrHarassment")
|
78 |
+
|
79 |
+
print("\n--- DeepSeek 分析結果 ---")
|
80 |
+
print(f"会話レベル: {conversation_level}")
|
81 |
+
print(f"ハラスメントの有無: {harassment_present}")
|
82 |
+
print(f"ハラスメントの種類: {harassment_type}")
|
83 |
+
print(f"繰り返しの程度: {repetition}")
|
84 |
+
print(f"会話の心地よさ: {pleasantConversation}")
|
85 |
+
print(f"非難またはハラスメントの程度: {blameOrHarassment}")
|
86 |
+
return jsonify({"results": results}),200
|
87 |
+
|
88 |
|
89 |
# 音声アップロード&解析エンドポイント
|
90 |
@app.route('/upload_audio', methods=['POST'])
|