Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -136,33 +136,44 @@ def process_relatorios(contador_csv_path, relatorio_csv_path):
|
|
136 |
|
137 |
|
138 |
def processar_relatorio(html_file, tarefa_files):
|
139 |
-
input_directory = "temp_files"
|
140 |
output_directory = "temp_files"
|
|
|
141 |
os.makedirs(input_directory, exist_ok=True)
|
142 |
os.makedirs(output_directory, exist_ok=True)
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
html_path = os.path.join(input_directory, "alunos.htm")
|
145 |
with open(html_path, "wb") as f:
|
146 |
f.write(html_file)
|
147 |
-
alunos_csv_path = os.path.join(output_directory, "alunos_fim.csv")
|
148 |
-
normalize_html_to_csv(html_path, alunos_csv_path)
|
149 |
|
150 |
for idx, tarefa_file in enumerate(tarefa_files):
|
151 |
tarefa_path = os.path.join(input_directory, f"tarefa_{idx}.xlsx")
|
152 |
with open(tarefa_path, "wb") as f:
|
153 |
f.write(tarefa_file)
|
|
|
|
|
|
|
|
|
154 |
normalize_multiple_excel_to_csv(input_directory, output_directory)
|
155 |
|
|
|
156 |
contador_csv_path = os.path.join(output_directory, "contador_tarefas.csv")
|
157 |
relatorio_csv_path = os.path.join(output_directory, "relatorio_final.csv")
|
158 |
process_all_tarefas_in_directory(output_directory, alunos_csv_path, contador_csv_path, relatorio_csv_path)
|
159 |
df = process_relatorios(contador_csv_path, relatorio_csv_path)
|
|
|
|
|
160 |
html_output_path = os.path.join(output_directory, "relatorio_final.html")
|
161 |
df.to_html(html_output_path, index=False)
|
162 |
-
return df.to_html(index=False), html_output_path
|
163 |
|
164 |
-
|
165 |
-
return file_path
|
166 |
|
167 |
# --- Interface Gradio ---
|
168 |
with gr.Blocks() as interface:
|
|
|
136 |
|
137 |
|
138 |
def processar_relatorio(html_file, tarefa_files):
|
139 |
+
input_directory = "temp_files" # Diret贸rio tempor谩rio para os arquivos
|
140 |
output_directory = "temp_files"
|
141 |
+
|
142 |
os.makedirs(input_directory, exist_ok=True)
|
143 |
os.makedirs(output_directory, exist_ok=True)
|
144 |
|
145 |
+
# Limpa o diret贸rio tempor谩rio antes de cada execu莽茫o (opcional, mas recomendado)
|
146 |
+
for filename in os.listdir(input_directory):
|
147 |
+
file_path = os.path.join(input_directory, filename)
|
148 |
+
if os.path.isfile(file_path):
|
149 |
+
os.remove(file_path)
|
150 |
+
|
151 |
+
# Salva os arquivos enviados
|
152 |
html_path = os.path.join(input_directory, "alunos.htm")
|
153 |
with open(html_path, "wb") as f:
|
154 |
f.write(html_file)
|
|
|
|
|
155 |
|
156 |
for idx, tarefa_file in enumerate(tarefa_files):
|
157 |
tarefa_path = os.path.join(input_directory, f"tarefa_{idx}.xlsx")
|
158 |
with open(tarefa_path, "wb") as f:
|
159 |
f.write(tarefa_file)
|
160 |
+
|
161 |
+
# Normaliza os arquivos
|
162 |
+
alunos_csv_path = os.path.join(output_directory, "alunos_fim.csv")
|
163 |
+
normalize_html_to_csv(html_path, alunos_csv_path)
|
164 |
normalize_multiple_excel_to_csv(input_directory, output_directory)
|
165 |
|
166 |
+
# Processa os dados e gera o relat贸rio
|
167 |
contador_csv_path = os.path.join(output_directory, "contador_tarefas.csv")
|
168 |
relatorio_csv_path = os.path.join(output_directory, "relatorio_final.csv")
|
169 |
process_all_tarefas_in_directory(output_directory, alunos_csv_path, contador_csv_path, relatorio_csv_path)
|
170 |
df = process_relatorios(contador_csv_path, relatorio_csv_path)
|
171 |
+
|
172 |
+
# Salva o relat贸rio em HTML
|
173 |
html_output_path = os.path.join(output_directory, "relatorio_final.html")
|
174 |
df.to_html(html_output_path, index=False)
|
|
|
175 |
|
176 |
+
return df.to_html(index=False), html_output_path
|
|
|
177 |
|
178 |
# --- Interface Gradio ---
|
179 |
with gr.Blocks() as interface:
|