Repository navigation
Expand file tree
/
Copy pathviz.py
More file actions
53 lines (42 loc) 路 1.96 KB
/
Copy pathviz.py
File metadata and controls
53 lines (42 loc) 路 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
import os
import streamlit as st
import streamlit.components.v1 as components
import pandas as pd
import sweetviz as sv
from io import StringIO
import requests
def app(title=None):
st.set_page_config(page_title="EDA com SweetViz", page_icon="馃幉", layout="wide")
st.title(title)
# Escolha da fonte de dados
option = st.radio("Selecione a fonte do CSV:", ("Upload de Arquivo", "Link da Web"))
df = None
sep = st.selectbox("Selecione o separador", ("Comma", "Tab", ";", ":"))
sep = "," if sep == "Comma" else "\t" if sep == "Tab" else ";" if sep == ";" else ":"
if option == "Upload de Arquivo":
uploaded_file = st.file_uploader("Escolha um arquivo CSV", type="csv")
if uploaded_file is not None:
df = pd.read_csv(StringIO(uploaded_file.getvalue().decode('utf-8')), sep=sep)
elif option == "Link da Web":
url = st.text_input("Cole aqui o link do CSV (ex: https://.../arquivo.csv)")
if url:
try:
response = requests.get(url)
response.raise_for_status() # Verifica se houve erro
df = pd.read_csv(StringIO(response.text), sep=sep)
except Exception as e:
st.error(f"Erro ao carregar o CSV da URL: {e}")
# Se o DataFrame foi carregado, mostra os dados e gera relat贸rio
if df is not None:
st.write("### Visualiza莽茫o inicial do CSV")
st.write(df.head())
# Gera an谩lise com Sweetviz
analysis = sv.analyze(df)
# Salva o relat贸rio em HTML
html_file = "output.html"
analysis.show_html(filepath=html_file, open_browser=False, layout='vertical', scale=1.0)
# Mostra dentro do Streamlit
with open(html_file, 'r', encoding='utf-8') as HtmlFile:
source_code = HtmlFile.read()
components.html(source_code, height=1200, width=1750, scrolling=True)
app(title='馃幉 EDA com SweetViz')