Spaces:
Runtime error
Runtime error
Update transcription.py
Browse files- __pycache__/transcription.cpython-310.pyc +0 -0
- app.py +21 -10
- transcription.py +5 -0
__pycache__/transcription.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/transcription.cpython-310.pyc and b/__pycache__/transcription.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -106,30 +106,41 @@ def reset_member():
|
|
| 106 |
def transcription():
|
| 107 |
global transcription_text
|
| 108 |
global total_audio
|
| 109 |
-
|
| 110 |
-
print(transcription_text)
|
| 111 |
-
if not os.path.exists(transcription_text):
|
| 112 |
try:
|
|
|
|
|
|
|
| 113 |
audio_directory = transcripter.merge_segments(total_audio,'/tmp/data/transcription_audio')
|
| 114 |
transcription_text = transcripter.create_transcription(audio_directory)
|
|
|
|
|
|
|
| 115 |
except Exception as e:
|
| 116 |
return jsonify({"error": str(e)}),500
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# AI分析エンドポイント
|
| 123 |
@app.route('/analyze',methods =['GET','POST'])
|
| 124 |
def analyze():
|
| 125 |
global transcription_text
|
| 126 |
-
|
|
|
|
| 127 |
try:
|
|
|
|
|
|
|
| 128 |
audio_directory = transcripter.merge_segments(total_audio,'/tmp/data/transcription_audio')
|
| 129 |
transcription_text = transcripter.create_transcription(audio_directory)
|
| 130 |
except Exception as e:
|
| 131 |
-
return jsonify({
|
| 132 |
-
|
| 133 |
analyzer = TextAnalyzer(transcription_text, harassment_keywords)
|
| 134 |
api_key = os.environ.get("DEEPSEEK")
|
| 135 |
if api_key is None:
|
|
|
|
| 106 |
def transcription():
|
| 107 |
global transcription_text
|
| 108 |
global total_audio
|
| 109 |
+
if not os.path.exists(transcription_text) or not transcription_text:
|
|
|
|
|
|
|
| 110 |
try:
|
| 111 |
+
if not total_audio or not os.path.exists(total_audio):
|
| 112 |
+
return jsonify({"error": "No audio segments provided"}),400
|
| 113 |
audio_directory = transcripter.merge_segments(total_audio,'/tmp/data/transcription_audio')
|
| 114 |
transcription_text = transcripter.create_transcription(audio_directory)
|
| 115 |
+
print("transcription")
|
| 116 |
+
print(transcription_text)
|
| 117 |
except Exception as e:
|
| 118 |
return jsonify({"error": str(e)}),500
|
| 119 |
+
try:
|
| 120 |
+
with open(transcription_text,'r',encoding='utf-8') as file:
|
| 121 |
+
file_content = file.read()
|
| 122 |
+
print(file_content)
|
| 123 |
+
return jsonify({'transcription': file_content}),200
|
| 124 |
+
except FileNotFoundError:
|
| 125 |
+
return jsonify({"error": "Transcription file not found"}), 404
|
| 126 |
+
except Exception as e:
|
| 127 |
+
return jsonify({"error": f"Unexpected error: {str(e)}"}), 500
|
| 128 |
+
|
| 129 |
|
| 130 |
# AI分析エンドポイント
|
| 131 |
@app.route('/analyze',methods =['GET','POST'])
|
| 132 |
def analyze():
|
| 133 |
global transcription_text
|
| 134 |
+
global total_audio
|
| 135 |
+
if not os.path.exists(transcription_text) or not transcription_text:
|
| 136 |
try:
|
| 137 |
+
if not total_audio:
|
| 138 |
+
return jsonify({"error": "No audio segments provided"}),400
|
| 139 |
audio_directory = transcripter.merge_segments(total_audio,'/tmp/data/transcription_audio')
|
| 140 |
transcription_text = transcripter.create_transcription(audio_directory)
|
| 141 |
except Exception as e:
|
| 142 |
+
return jsonify({"error": str(e)}),500
|
| 143 |
+
|
| 144 |
analyzer = TextAnalyzer(transcription_text, harassment_keywords)
|
| 145 |
api_key = os.environ.get("DEEPSEEK")
|
| 146 |
if api_key is None:
|
transcription.py
CHANGED
|
@@ -4,6 +4,7 @@ from pydub import AudioSegment
|
|
| 4 |
import string
|
| 5 |
import random
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
|
| 8 |
# Matplotlibのキャッシュディレクトリを変更
|
| 9 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
|
@@ -65,6 +66,10 @@ class TranscriptionMaker():
|
|
| 65 |
|
| 66 |
if len(files) <= 1:
|
| 67 |
print('No need to merge')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return output_dir
|
| 69 |
|
| 70 |
combined_audio = AudioSegment.empty()
|
|
|
|
| 4 |
import string
|
| 5 |
import random
|
| 6 |
from datetime import datetime
|
| 7 |
+
import shutil
|
| 8 |
|
| 9 |
# Matplotlibのキャッシュディレクトリを変更
|
| 10 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
|
|
|
| 66 |
|
| 67 |
if len(files) <= 1:
|
| 68 |
print('No need to merge')
|
| 69 |
+
single_file_path = os.path.join(segments_dir, files[0])
|
| 70 |
+
destination_path = os.path.join(output_dir, files[0])
|
| 71 |
+
shutil.copy(single_file_path, destination_path)
|
| 72 |
+
print(f"ファイル {files[0]} を {output_dir} に移動しました。")
|
| 73 |
return output_dir
|
| 74 |
|
| 75 |
combined_audio = AudioSegment.empty()
|