Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,46 +55,39 @@ def verificar_arquivo(file):
|
|
| 55 |
with open(file.name, 'r', encoding='utf-8-sig') as csvfile:
|
| 56 |
reader = csv.reader(csvfile)
|
| 57 |
for row in reader:
|
| 58 |
-
|
| 59 |
-
numero = str(row[0]).strip()
|
| 60 |
-
# Remove qualquer notação científica
|
| 61 |
-
if 'E' in numero or 'e' in numero:
|
| 62 |
-
numero = '{:.0f}'.format(float(numero))
|
| 63 |
resultados.append(verificar_numero(numero))
|
| 64 |
elif file.name.endswith('.txt'):
|
| 65 |
with open(file.name, 'r', encoding='utf-8-sig') as txtfile:
|
| 66 |
for line in txtfile:
|
| 67 |
-
numero =
|
| 68 |
-
if 'E' in numero or 'e' in numero:
|
| 69 |
-
numero = '{:.0f}'.format(float(numero))
|
| 70 |
resultados.append(verificar_numero(numero))
|
| 71 |
else:
|
| 72 |
return "Formato de arquivo não suportado. Use .txt ou .csv."
|
| 73 |
-
|
| 74 |
-
df = pd.DataFrame(resultados)
|
| 75 |
-
# Força a coluna "Número" a ser string
|
| 76 |
-
df["Número"] = df["Número"].astype(str)
|
| 77 |
-
# Remove notação científica se presente
|
| 78 |
-
df["Número"] = df["Número"].apply(lambda x: '{:.0f}'.format(float(x)) if 'E' in x or 'e' in x else x)
|
| 79 |
-
return df
|
| 80 |
except Exception as e:
|
| 81 |
return f"Erro ao processar o arquivo: {str(e)}"
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
def baixar_resultados(file):
|
| 84 |
resultados = verificar_arquivo(file)
|
| 85 |
if isinstance(resultados, pd.DataFrame):
|
| 86 |
-
#
|
| 87 |
resultados["Número"] = resultados["Número"].astype(str)
|
| 88 |
-
resultados["Número"] = resultados["Número"].apply(
|
| 89 |
-
lambda x: '{:.0f}'.format(float(x)) if 'E' in x or 'e' in x else x
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
resultados = resultados[["Número", "Nome", "Tipo", "Email", "Categoria"]]
|
| 93 |
|
| 94 |
-
#
|
| 95 |
-
pd.set_option('display.float_format', lambda x: '%.0f' % x)
|
| 96 |
-
|
| 97 |
file_path = "resultados_validacao.csv"
|
|
|
|
|
|
|
| 98 |
resultados.to_csv(
|
| 99 |
file_path,
|
| 100 |
index=False,
|
|
@@ -109,17 +102,7 @@ def baixar_resultados(file):
|
|
| 109 |
def processar(numero, file):
|
| 110 |
resultados = processar_input(numero, file)
|
| 111 |
if isinstance(resultados, pd.DataFrame):
|
| 112 |
-
# Força os números a serem strings e remove notação científica
|
| 113 |
-
resultados["Número"] = resultados["Número"].astype(str)
|
| 114 |
-
resultados["Número"] = resultados["Número"].apply(
|
| 115 |
-
lambda x: '{:.0f}'.format(float(x)) if 'E' in x or 'e' in x else x
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
resultados = resultados[["Número", "Nome", "Tipo", "Email", "Categoria"]]
|
| 119 |
-
|
| 120 |
-
# Configuração do pandas para evitar notação científica
|
| 121 |
-
pd.set_option('display.float_format', lambda x: '%.0f' % x)
|
| 122 |
-
|
| 123 |
resultados.to_csv(
|
| 124 |
"resultados_validacao.csv",
|
| 125 |
index=False,
|
|
|
|
| 55 |
with open(file.name, 'r', encoding='utf-8-sig') as csvfile:
|
| 56 |
reader = csv.reader(csvfile)
|
| 57 |
for row in reader:
|
| 58 |
+
numero = row[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
resultados.append(verificar_numero(numero))
|
| 60 |
elif file.name.endswith('.txt'):
|
| 61 |
with open(file.name, 'r', encoding='utf-8-sig') as txtfile:
|
| 62 |
for line in txtfile:
|
| 63 |
+
numero = line.strip()
|
|
|
|
|
|
|
| 64 |
resultados.append(verificar_numero(numero))
|
| 65 |
else:
|
| 66 |
return "Formato de arquivo não suportado. Use .txt ou .csv."
|
| 67 |
+
return pd.DataFrame(resultados)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
return f"Erro ao processar o arquivo: {str(e)}"
|
| 70 |
|
| 71 |
+
def processar_input(numero, file):
|
| 72 |
+
if numero:
|
| 73 |
+
resultado = verificar_numero(numero)
|
| 74 |
+
return pd.DataFrame([resultado])
|
| 75 |
+
elif file:
|
| 76 |
+
return verificar_arquivo(file)
|
| 77 |
+
else:
|
| 78 |
+
return "Forneça um número ou um arquivo para validação."
|
| 79 |
+
|
| 80 |
def baixar_resultados(file):
|
| 81 |
resultados = verificar_arquivo(file)
|
| 82 |
if isinstance(resultados, pd.DataFrame):
|
| 83 |
+
# Garantir que os números sejam strings para preservar integridade
|
| 84 |
resultados["Número"] = resultados["Número"].astype(str)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
resultados = resultados[["Número", "Nome", "Tipo", "Email", "Categoria"]]
|
| 86 |
|
| 87 |
+
# Caminho para salvar o arquivo
|
|
|
|
|
|
|
| 88 |
file_path = "resultados_validacao.csv"
|
| 89 |
+
|
| 90 |
+
# Definir encoding como 'utf-8-sig' para incluir BOM e manter acentuação
|
| 91 |
resultados.to_csv(
|
| 92 |
file_path,
|
| 93 |
index=False,
|
|
|
|
| 102 |
def processar(numero, file):
|
| 103 |
resultados = processar_input(numero, file)
|
| 104 |
if isinstance(resultados, pd.DataFrame):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
resultados = resultados[["Número", "Nome", "Tipo", "Email", "Categoria"]]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
resultados.to_csv(
|
| 107 |
"resultados_validacao.csv",
|
| 108 |
index=False,
|