2.1
Browse files
app.py
CHANGED
@@ -31,40 +31,48 @@ def allowed_file(filename):
|
|
31 |
def run_transcription(audio_path, job_id):
|
32 |
"""Executa a transcrição em background"""
|
33 |
try:
|
|
|
34 |
processing_status[job_id]['status'] = 'processing'
|
35 |
processing_status[job_id]['message'] = 'Iniciando transcrição...'
|
36 |
-
|
37 |
-
# Executar o script de transcrição
|
38 |
result = subprocess.run(
|
39 |
['python', 'transcriptor.py', audio_path],
|
40 |
capture_output=True,
|
41 |
text=True,
|
42 |
cwd='.'
|
43 |
)
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
if result.returncode == 0:
|
46 |
-
# Encontrar o arquivo JSON gerado
|
47 |
-
base_name = os.path.splitext(os.path.basename(audio_path))[0]
|
48 |
-
json_file = f"{base_name}_transcricao.json"
|
49 |
-
|
50 |
if os.path.exists(json_file):
|
51 |
-
# Mover para pasta de outputs
|
52 |
output_path = os.path.join(OUTPUT_FOLDER, json_file)
|
53 |
os.rename(json_file, output_path)
|
54 |
-
|
55 |
processing_status[job_id]['status'] = 'completed'
|
56 |
processing_status[job_id]['message'] = 'Transcrição concluída com sucesso!'
|
57 |
processing_status[job_id]['output_file'] = json_file
|
|
|
58 |
else:
|
59 |
processing_status[job_id]['status'] = 'error'
|
60 |
processing_status[job_id]['message'] = 'Arquivo JSON não foi gerado'
|
|
|
61 |
else:
|
62 |
processing_status[job_id]['status'] = 'error'
|
63 |
processing_status[job_id]['message'] = f'Erro na transcrição: {result.stderr}'
|
64 |
-
|
|
|
65 |
except Exception as e:
|
66 |
processing_status[job_id]['status'] = 'error'
|
67 |
processing_status[job_id]['message'] = f'Erro interno: {str(e)}'
|
|
|
68 |
|
69 |
@app.route('/')
|
70 |
def index():
|
@@ -75,17 +83,17 @@ def upload_file():
|
|
75 |
if 'file' not in request.files:
|
76 |
flash('Nenhum arquivo selecionado')
|
77 |
return redirect(request.url)
|
78 |
-
|
79 |
file = request.files['file']
|
80 |
if file.filename == '':
|
81 |
flash('Nenhum arquivo selecionado')
|
82 |
return redirect(request.url)
|
83 |
-
|
84 |
if file and allowed_file(file.filename):
|
85 |
filename = secure_filename(file.filename)
|
86 |
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
87 |
file.save(filepath)
|
88 |
-
|
89 |
# Criar job ID único
|
90 |
job_id = f"{int(time.time())}_{filename}"
|
91 |
processing_status[job_id] = {
|
@@ -93,14 +101,14 @@ def upload_file():
|
|
93 |
'message': 'Aguardando processamento...',
|
94 |
'filename': filename
|
95 |
}
|
96 |
-
|
97 |
# Iniciar transcrição em background
|
98 |
thread = threading.Thread(target=run_transcription, args=(filepath, job_id))
|
99 |
thread.daemon = True
|
100 |
thread.start()
|
101 |
-
|
102 |
return render_template('processing.html', job_id=job_id, filename=filename)
|
103 |
-
|
104 |
else:
|
105 |
flash('Formato de arquivo não suportado. Use: MP3, WAV, MP4, M4A, FLAC, OGG')
|
106 |
return redirect(url_for('index'))
|
@@ -127,7 +135,6 @@ def download_file(filename):
|
|
127 |
|
128 |
@app.route('/results')
|
129 |
def results():
|
130 |
-
"""Página para listar todos os resultados disponíveis"""
|
131 |
output_files = []
|
132 |
if os.path.exists(OUTPUT_FOLDER):
|
133 |
for filename in os.listdir(OUTPUT_FOLDER):
|
@@ -136,11 +143,11 @@ def results():
|
|
136 |
file_stats = os.stat(filepath)
|
137 |
output_files.append({
|
138 |
'name': filename,
|
139 |
-
'size': round(file_stats.st_size / 1024, 2),
|
140 |
'modified': time.ctime(file_stats.st_mtime)
|
141 |
})
|
142 |
-
|
143 |
return render_template('results.html', files=output_files)
|
144 |
|
145 |
if __name__ == '__main__':
|
146 |
-
app.run(host='0.0.0.0', port=7860, debug=False)
|
|
|
31 |
def run_transcription(audio_path, job_id):
|
32 |
"""Executa a transcrição em background"""
|
33 |
try:
|
34 |
+
print(f"[{job_id}] Iniciando transcrição para {audio_path}")
|
35 |
processing_status[job_id]['status'] = 'processing'
|
36 |
processing_status[job_id]['message'] = 'Iniciando transcrição...'
|
37 |
+
|
|
|
38 |
result = subprocess.run(
|
39 |
['python', 'transcriptor.py', audio_path],
|
40 |
capture_output=True,
|
41 |
text=True,
|
42 |
cwd='.'
|
43 |
)
|
44 |
+
|
45 |
+
print(f"[{job_id}] Transcrição finalizada com código {result.returncode}")
|
46 |
+
if result.stdout:
|
47 |
+
print(f"[{job_id}] STDOUT: {result.stdout}")
|
48 |
+
if result.stderr:
|
49 |
+
print(f"[{job_id}] STDERR: {result.stderr}")
|
50 |
+
|
51 |
+
base_name = os.path.splitext(os.path.basename(audio_path))[0]
|
52 |
+
json_file = f"{base_name}_transcricao.json"
|
53 |
+
|
54 |
if result.returncode == 0:
|
|
|
|
|
|
|
|
|
55 |
if os.path.exists(json_file):
|
|
|
56 |
output_path = os.path.join(OUTPUT_FOLDER, json_file)
|
57 |
os.rename(json_file, output_path)
|
58 |
+
|
59 |
processing_status[job_id]['status'] = 'completed'
|
60 |
processing_status[job_id]['message'] = 'Transcrição concluída com sucesso!'
|
61 |
processing_status[job_id]['output_file'] = json_file
|
62 |
+
print(f"[{job_id}] JSON salvo em: {output_path}")
|
63 |
else:
|
64 |
processing_status[job_id]['status'] = 'error'
|
65 |
processing_status[job_id]['message'] = 'Arquivo JSON não foi gerado'
|
66 |
+
print(f"[{job_id}] ERRO: JSON não encontrado: {json_file}")
|
67 |
else:
|
68 |
processing_status[job_id]['status'] = 'error'
|
69 |
processing_status[job_id]['message'] = f'Erro na transcrição: {result.stderr}'
|
70 |
+
print(f"[{job_id}] ERRO na execução do script")
|
71 |
+
|
72 |
except Exception as e:
|
73 |
processing_status[job_id]['status'] = 'error'
|
74 |
processing_status[job_id]['message'] = f'Erro interno: {str(e)}'
|
75 |
+
print(f"[{job_id}] EXCEPTION: {str(e)}")
|
76 |
|
77 |
@app.route('/')
|
78 |
def index():
|
|
|
83 |
if 'file' not in request.files:
|
84 |
flash('Nenhum arquivo selecionado')
|
85 |
return redirect(request.url)
|
86 |
+
|
87 |
file = request.files['file']
|
88 |
if file.filename == '':
|
89 |
flash('Nenhum arquivo selecionado')
|
90 |
return redirect(request.url)
|
91 |
+
|
92 |
if file and allowed_file(file.filename):
|
93 |
filename = secure_filename(file.filename)
|
94 |
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
95 |
file.save(filepath)
|
96 |
+
|
97 |
# Criar job ID único
|
98 |
job_id = f"{int(time.time())}_{filename}"
|
99 |
processing_status[job_id] = {
|
|
|
101 |
'message': 'Aguardando processamento...',
|
102 |
'filename': filename
|
103 |
}
|
104 |
+
|
105 |
# Iniciar transcrição em background
|
106 |
thread = threading.Thread(target=run_transcription, args=(filepath, job_id))
|
107 |
thread.daemon = True
|
108 |
thread.start()
|
109 |
+
|
110 |
return render_template('processing.html', job_id=job_id, filename=filename)
|
111 |
+
|
112 |
else:
|
113 |
flash('Formato de arquivo não suportado. Use: MP3, WAV, MP4, M4A, FLAC, OGG')
|
114 |
return redirect(url_for('index'))
|
|
|
135 |
|
136 |
@app.route('/results')
|
137 |
def results():
|
|
|
138 |
output_files = []
|
139 |
if os.path.exists(OUTPUT_FOLDER):
|
140 |
for filename in os.listdir(OUTPUT_FOLDER):
|
|
|
143 |
file_stats = os.stat(filepath)
|
144 |
output_files.append({
|
145 |
'name': filename,
|
146 |
+
'size': round(file_stats.st_size / 1024, 2),
|
147 |
'modified': time.ctime(file_stats.st_mtime)
|
148 |
})
|
149 |
+
|
150 |
return render_template('results.html', files=output_files)
|
151 |
|
152 |
if __name__ == '__main__':
|
153 |
+
app.run(host='0.0.0.0', port=7860, debug=False)
|