17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 | def main():
'''
Função principal do app. Inicia o menu lateral e as páginas. Interface do usuário.
O menu lateral é criado com a função option_menu do pacote streamlit_option_menu.
As páginas são chamadas a partir da opção selecionada no menu lateral.
'''
main_folder_path = "etc"
# Side Menu
with st.sidebar:
option = option_menu("Versão Web v.1.0.0",
options=["Sobre",
"Áudio",
"Vídeo",
"Zip",
"Analisar",
"Configurações"],
# Icons from https://icons.getbootstrap.com/
icons=['house',
'file-earmark-music-fill',
'file-play-fill',
'file-zip-fill',
'binoculars',
'wrench'],
menu_icon="cloud", default_index=0,
)
# Pages
if option == 'Sobre':
about.about()
# Option Transcribe Files
elif option == "Áudio" or option == "Vídeo" or option == "Zip":
st.subheader('Transcrever Arquivos')
type_model = settings.select_model('web')
# Only audio files
if option == "Áudio":
uploaded_file_list = st.file_uploader('Selecione os arquivos de áudio',
type=["opus","wav","mp3","ogg","wma"],
accept_multiple_files=True)
# Only video files
elif option == "Vídeo":
uploaded_file_list = st.file_uploader('Selecione os arquivos de vídeo',
type=["mp4", "m4a", "avi", "mov", "wmv"],
accept_multiple_files=True)
# Only zip files
elif option == "Zip":
uploaded_file_list = st.file_uploader('Selecione os arquivos de áudio ou vídeo',
type=["zip", "ufed"],
accept_multiple_files=False)
# Check if files were uploaded
if uploaded_file_list is not None:
if st.button('Transcrever'):
# Create token
token = token_leia.get_token_leia()
# Crate token folders
token_folder_path, database_folder_path, temporary_folder_path, original_folder_path = folders.create_folders(token, main_folder_path)
if option == "Zip":
with open(os.path.join(temporary_folder_path,
uploaded_file_list.name), "wb") as f:
f.write((uploaded_file_list).getbuffer())
zip_file_list = extract_zip.extract_media_files(os.path.join(temporary_folder_path,
uploaded_file_list.name),
original_folder_path)
#st.write(zip_file_list)
else:
for file in uploaded_file_list:
# Save all files with original name
with open(os.path.join(original_folder_path, file.name),"wb") as f:
f.write((file).getbuffer())
# Transcribe folder
with st.spinner(f"Transcrevendo Arquivos ... 💫"):
# Transcribe file list
df = pd.DataFrame(transcribe.transcribe(original_folder_path, type_model))
st.dataframe(df)
# Write to database
database.write_to_db(database_folder_path, token, df)
# Print Token
st.title("IMPORTANTE ⚠️")
st.subheader(f"Copie e GUARDE o Token a Seguir. ")
st.text("Você precisará dele para acessar as transcrições.")
st.code(token)
st.markdown("O Token é um código único que identifica essa trasncrição."
"Ele é gerado automaticamente e é único para cada conjunto de transcrições."
"NÃO O PERCA! Sem o Token, não será possível acessar essas transcrições."
"Os arquivos de áudio e vídeo não são salvos no banco de dados."
"As transcrições ficam salvas no banco de dados por 30 dias."
"Após esse período, os dados são apagados."
"Você pode acessar as transcrições a qualquer momento, basta inserir o Token no menu Analisar."
"Você poderá apagar as transcrições a qualquer momento no menu Configurações."
"Acesse o menu Analisar ao lado e insira o token.")
# Option Analize
elif option == 'Analisar':
st.subheader('Analisar')
token = st.text_input("Informe o Token do caso que deseja analisar")
# Check if token exists
if token:
token_folder_path, database_folder_path, temporary_folder_path, original_folder_path = folders.get_folders(token, main_folder_path)
analize.analize(token, database_folder_path, temporary_folder_path, original_folder_path)
# Option Settings
elif option == 'Configurações':
st.header('Configurações')
st.subheader("Remove Tokens")
token = st.text_input("Informe o Token das trancrições que deseja remover")
# Check if token exists
if token:
# Check if like secrete token
if token == settings.read_secret_token('secret-token.txt'):
settings.install_models('web')
if os.path.exists(main_folder_path):
if st.button('Remover Todos os Tokens'):
settings.remove_token(main_folder_path)
else:
try:
token_folder_path, database_folder_path, temporary_folder_path, original_folder_path = folders.get_folders(token, main_folder_path)
settings.remove_token(token_folder_path)
st.success("Transcrições removidas com sucesso!")
except:
st.error("Token não encontrado. Verifique se o token está correto.")
|