drguilhermeapolinario commited on
Commit
b44df07
·
verified ·
1 Parent(s): 1835dcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -36
app.py CHANGED
@@ -1,5 +1,6 @@
1
- """_summary_
2
  LIMPEZA E VISUALIZAÇÃO DE CSV
 
3
  Returns:
4
  DATAFRAMES
5
  """
@@ -15,7 +16,7 @@ from streamlit_extras.stylable_container import stylable_container
15
  from streamlit_folium import folium_static
16
  from streamlit_option_menu import option_menu
17
 
18
- from data_cleaning import criar_dataframe, iniciar, limpa_rci1, limpa_rci2, separa_grupos, renomear_escola, limpar_dfs, processar_arquivo
19
 
20
  st.set_page_config(
21
  page_title="Dashboard UBS Flamengo",
@@ -24,7 +25,6 @@ st.set_page_config(
24
  initial_sidebar_state="expanded",
25
  )
26
 
27
-
28
  def processar_arquivo(file):
29
  """
30
  A function that processes the uploaded file by writing it to a temporary CSV file,
@@ -32,15 +32,20 @@ def processar_arquivo(file):
32
  Returns:
33
  - dataframes: the processed dataframes generated from the uploaded file
34
  """
35
- with open("temp.csv", "wb") as f:
36
- f.write(file.getbuffer())
37
- csv_st = iniciar("temp.csv")
38
- clean_txt = limpa_rci(csv_st)
39
  grupos_encontrados = separa_grupos(clean_txt)
40
- dfs = criar_dataframe(grupos_encontrados)
 
 
 
41
 
42
- return dfs
 
 
 
43
 
 
44
 
45
  # Inicializar variáveis dos DataFrames como None
46
  DF_DATA = None
@@ -56,11 +61,6 @@ DF_TRANSGEN = None
56
  # Upload de arquivo CSV na barra lateral
57
  uploaded_file = st.sidebar.file_uploader("Escolha um arquivo CSV", type="csv")
58
 
59
- def processar_arquivo(uploaded_file):
60
- # Função que processa o arquivo CSV e retorna os DataFrames
61
- # (Esta função deve ser importada ou definida aqui)
62
- pass
63
-
64
  if uploaded_file is not None:
65
  dataframes = processar_arquivo(uploaded_file)
66
 
@@ -130,7 +130,6 @@ def gerar_resumo_df():
130
  # Mostrar o resumo no Streamlit
131
  st.text(gerar_resumo_df())
132
 
133
-
134
  #######################################
135
  #######################################
136
  ############ BANNER ##################
@@ -154,7 +153,6 @@ with stylable_container(
154
  ):
155
  st.image("./banner.png")
156
 
157
-
158
  #######################################
159
  ############ BANNER ##################
160
  #######################################
@@ -166,7 +164,6 @@ with c1:
166
  st.markdown(
167
  """
168
  ## Dashboard UBS Flamengo
169
-
170
  ###### :brain: _by Dr. Guilherme Apolinário_
171
 
172
  #### Bem-vindo! :wave:
@@ -191,7 +188,6 @@ with c2:
191
  st.image("./graph1.png")
192
  st.divider()
193
 
194
-
195
  ###########################################
196
  ###########################################
197
  ###########################################
@@ -206,7 +202,6 @@ st.sidebar.markdown(
206
  - Análise de dados do relatório de cadastro individual.
207
  - Iniciativa - Ubs Flamengo
208
  - Acesso livre
209
-
210
  ### Links:
211
  ##
212
  ##### - [PEC SUS](https://sape.pecsus.com.br/) 📝
@@ -232,7 +227,6 @@ st.markdown(
232
  )
233
  st.divider()
234
 
235
-
236
  st.markdown(
237
  """
238
  ### :world_map: **Conhecendo a área de abrangencia daUBS Flamengo: (IBGE 2022)**
@@ -303,14 +297,6 @@ st.markdown(
303
  ## Dados de saúde Relatório de cadastro individual.
304
  """
305
  )
306
- #
307
- #
308
- #
309
- #
310
- #
311
- #
312
- #
313
-
314
 
315
  if uploaded_file is not None:
316
  dataframes = processar_arquivo(uploaded_file)
@@ -332,10 +318,6 @@ if uploaded_file is not None:
332
  df["Descrição"] = df["Descrição"].str.capitalize()
333
  else:
334
  st.sidebar.info("Adicione um arquivo .csv.")
335
- #
336
- #
337
- #
338
- #
339
 
340
  def criar_grafico_personalizado(df, x_col, y_col, titulo):
341
  """
@@ -515,7 +497,6 @@ st.info(
515
 
516
  add_vertical_space(1)
517
 
518
-
519
  with stylable_container(
520
  key="brain",
521
  css_styles="""
@@ -530,6 +511,7 @@ with stylable_container(
530
  """,
531
  ):
532
  st.image("./brain.png")
 
533
  # Widget expander para interação da IA
534
  with st.expander(" Converse com o 🤖 Zé Flamengo", expanded=True):
535
  client = Groq(
@@ -560,9 +542,7 @@ with st.expander(" Converse com o 🤖 Zé Flamengo", expanded=True):
560
  evite conversar sobre outros temas, sempre retornando ao tema da
561
  conversa.
562
  Aqui estão os resumos dos dataframes disponíveis:
563
-
564
  {RESUMO_DF}
565
-
566
  Use essas informações para responder às perguntas do usuário.
567
  Regras:
568
  1- Seja sempre cortês.
@@ -592,7 +572,6 @@ with st.expander(" Converse com o 🤖 Zé Flamengo", expanded=True):
592
  else:
593
  st.warning("Por favor, digite uma pergunta antes de enviar.")
594
 
595
-
596
  # Adicione este código fora do expander para evitar a reexecução do script ao pressionar Enter
597
  if "USER_CHAT_input" in st.session_state and st.session_state.USER_CHAT_input:
598
  st.session_state.USER_CHAT_input = ""
 
1
+ """
2
  LIMPEZA E VISUALIZAÇÃO DE CSV
3
+
4
  Returns:
5
  DATAFRAMES
6
  """
 
16
  from streamlit_folium import folium_static
17
  from streamlit_option_menu import option_menu
18
 
19
+ from data_cleaning import criar_dataframe, iniciar, limpa_rci1, limpa_rci2, separa_grupos, renomear_escola, limpar_dfs
20
 
21
  st.set_page_config(
22
  page_title="Dashboard UBS Flamengo",
 
25
  initial_sidebar_state="expanded",
26
  )
27
 
 
28
  def processar_arquivo(file):
29
  """
30
  A function that processes the uploaded file by writing it to a temporary CSV file,
 
32
  Returns:
33
  - dataframes: the processed dataframes generated from the uploaded file
34
  """
35
+ csv_st = iniciar(file)
36
+ clean_txt = limpa_rci1(csv_st)
 
 
37
  grupos_encontrados = separa_grupos(clean_txt)
38
+ dataframes = criar_dataframe(grupos_encontrados)
39
+
40
+ # Renomear descrições do DataFrame de escolaridade
41
+ dataframes["Escola"] = renomear_escola(dataframes["Escola"])
42
 
43
+ # Aplicar limpeza final nos DataFrames
44
+ clean_final = r"(\sativ\w+)|(\sde\scid.+o)|(iciê.+ia)|((?<=rans)gên.+o|omem|ulher|ário|Homoss.+\(|\))|(\d{10}\s-\s)"
45
+ substituicao = ""
46
+ dataframes = limpar_dfs(dataframes, clean_final, substituicao)
47
 
48
+ return dataframes
49
 
50
  # Inicializar variáveis dos DataFrames como None
51
  DF_DATA = None
 
61
  # Upload de arquivo CSV na barra lateral
62
  uploaded_file = st.sidebar.file_uploader("Escolha um arquivo CSV", type="csv")
63
 
 
 
 
 
 
64
  if uploaded_file is not None:
65
  dataframes = processar_arquivo(uploaded_file)
66
 
 
130
  # Mostrar o resumo no Streamlit
131
  st.text(gerar_resumo_df())
132
 
 
133
  #######################################
134
  #######################################
135
  ############ BANNER ##################
 
153
  ):
154
  st.image("./banner.png")
155
 
 
156
  #######################################
157
  ############ BANNER ##################
158
  #######################################
 
164
  st.markdown(
165
  """
166
  ## Dashboard UBS Flamengo
 
167
  ###### :brain: _by Dr. Guilherme Apolinário_
168
 
169
  #### Bem-vindo! :wave:
 
188
  st.image("./graph1.png")
189
  st.divider()
190
 
 
191
  ###########################################
192
  ###########################################
193
  ###########################################
 
202
  - Análise de dados do relatório de cadastro individual.
203
  - Iniciativa - Ubs Flamengo
204
  - Acesso livre
 
205
  ### Links:
206
  ##
207
  ##### - [PEC SUS](https://sape.pecsus.com.br/) 📝
 
227
  )
228
  st.divider()
229
 
 
230
  st.markdown(
231
  """
232
  ### :world_map: **Conhecendo a área de abrangencia daUBS Flamengo: (IBGE 2022)**
 
297
  ## Dados de saúde Relatório de cadastro individual.
298
  """
299
  )
 
 
 
 
 
 
 
 
300
 
301
  if uploaded_file is not None:
302
  dataframes = processar_arquivo(uploaded_file)
 
318
  df["Descrição"] = df["Descrição"].str.capitalize()
319
  else:
320
  st.sidebar.info("Adicione um arquivo .csv.")
 
 
 
 
321
 
322
  def criar_grafico_personalizado(df, x_col, y_col, titulo):
323
  """
 
497
 
498
  add_vertical_space(1)
499
 
 
500
  with stylable_container(
501
  key="brain",
502
  css_styles="""
 
511
  """,
512
  ):
513
  st.image("./brain.png")
514
+
515
  # Widget expander para interação da IA
516
  with st.expander(" Converse com o 🤖 Zé Flamengo", expanded=True):
517
  client = Groq(
 
542
  evite conversar sobre outros temas, sempre retornando ao tema da
543
  conversa.
544
  Aqui estão os resumos dos dataframes disponíveis:
 
545
  {RESUMO_DF}
 
546
  Use essas informações para responder às perguntas do usuário.
547
  Regras:
548
  1- Seja sempre cortês.
 
572
  else:
573
  st.warning("Por favor, digite uma pergunta antes de enviar.")
574
 
 
575
  # Adicione este código fora do expander para evitar a reexecução do script ao pressionar Enter
576
  if "USER_CHAT_input" in st.session_state and st.session_state.USER_CHAT_input:
577
  st.session_state.USER_CHAT_input = ""