Download app.py from AI-Dashboards/CP.Matplotlib.NetworkX.Streamlit.PyVis.Graphviz: direct link, hf CLI and curl.
- Browser
- Download file 3.71 kB
-
https://huggingface.co/spaces/AI-Dashboards/CP.Matplotlib.NetworkX.Streamlit.PyVis.Graphviz/resolve/635f998c44e6fcfd3f66a31dac46bd3cd5b1e8a8/app.py
- Command line
-
hf download hf://spaces/AI-Dashboards/CP.Matplotlib.NetworkX.Streamlit.PyVis.Graphviz@635f998c44e6fcfd3f66a31dac46bd3cd5b1e8a8/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AI-Dashboards/CP.Matplotlib.NetworkX.Streamlit.PyVis.Graphviz/resolve/635f998c44e6fcfd3f66a31dac46bd3cd5b1e8a8/app.py
3.71 kB
| import streamlit as st | |
| import streamlit.components.v1 as components | |
| import networkx as nx | |
| import matplotlib.pyplot as plt | |
| from pyvis.network import Network | |
| import got | |
| import numpy as np | |
| import pandas as pd | |
| import time | |
| import re | |
| import graphviz as graphviz | |
| import pydeck as pdk | |
| from st_click_detector import click_detector | |
| st.graphviz_chart(''' | |
| digraph { | |
| PR0001INCOME -> AbleToBuyOnlyNecessities | |
| PR0001INCOME -> DifficultyBuyingNecessities | |
| PR0001INCOME -> DifficultyWithMoneyManagement | |
| PR0001INCOME -> LowNoIncome | |
| PR0001INCOME -> UninsuredMedicalExpenses | |
| } | |
| ''') | |
| st.graphviz_chart(''' | |
| digraph { | |
| PR0012MENTALHEALTH -> Apprehension -> Undefined -> Fear -> Anxious | |
| PR0012MENTALHEALTH -> Attempts -> Suicide -> Homicide | |
| PR0012MENTALHEALTH -> Difficulty -> Managing -> Anger | |
| PR0012MENTALHEALTH -> Difficulty -> Managing -> Stress | |
| PR0012MENTALHEALTH -> Expresses -> Suicidal -> Homicidal -> Thoughts | |
| PR0012MENTALHEALTH -> False -> Beliefs -> Delusions | |
| PR0012MENTALHEALTH -> False -> Perceptions -> Hallucinations -> Illusions | |
| PR0012MENTALHEALTH -> FlatAffect -> LackofEmotion | |
| PR0012MENTALHEALTH -> Irritable -> Agitated -> Aggressive | |
| PR0012MENTALHEALTH -> LossofInterest -> Involvementin -> ActivitiesSelfCare | |
| PR0012MENTALHEALTH -> MoodSwings | |
| PR0012MENTALHEALTH -> Narrowedto -> Scattered -> Attention -> Focus | |
| PR0012MENTALHEALTH -> Purposeless -> Compulsive -> RepetitiveActivity | |
| PR0012MENTALHEALTH -> Sadness -> Hopelessness -> Decreased -> SelfEsteem | |
| PR0012MENTALHEALTH -> Somatic -> Complaints -> Fatigue | |
| } | |
| ''') | |
| df = pd.read_csv("testfile.csv") | |
| def convert_df(df): | |
| return df.to_csv().encode('utf-8') | |
| csv = convert_df(df) | |
| st.download_button( | |
| "Press to Download", | |
| csv, | |
| "testfile.csv", | |
| "text/csv", | |
| key='download-csv' | |
| ) | |
| st.title('Streamlit Visualization') | |
| dataframe = pd.DataFrame(np.random.randn(10, 20), | |
| columns = ('col %d' % i | |
| for i in range(20))) | |
| st.write(dataframe) | |
| dataframe = pd.DataFrame(np.random.randn(10, 5), | |
| columns = ('col %d' % i | |
| for i in range(5))) | |
| dataframe | |
| st.write('This is a line_chart.') | |
| st.line_chart(dataframe) | |
| st.write('This is a area_chart.') | |
| st.area_chart(dataframe) | |
| st.write('This is a bar_chart.') | |
| st.bar_chart(dataframe) | |
| st.write('Map data') | |
| data_of_map = pd.DataFrame( | |
| np.random.randn(1000, 2) / [60, 60] + [36.66, -121.6], | |
| columns = ['latitude', 'longitude']) | |
| st.map(data_of_map) | |
| image = Image.open('picture.jpg') | |
| st.image(image, caption = 'This is a picture', use_column_width = True) | |
| st.title('Pyvis VisJS DOTlang Legend') | |
| Network(notebook=True) | |
| # make Network show itself with repr_html | |
| def net_repr_html(self): | |
| nodes, edges, height, width, options = self.get_network_data() | |
| html = self.template.render(height=height, width=width, nodes=nodes, edges=edges, options=options) | |
| return html | |
| Network._repr_html_ = net_repr_html | |
| st.sidebar.title('Choose your favorite Graph') | |
| option=st.sidebar.selectbox('select graph',('Simple','Karate', 'GOT')) | |
| physics=st.sidebar.checkbox('add physics interactivity?') | |
| got.simple_func(physics) | |
| if option=='Simple': | |
| HtmlFile = open("test.html", 'r', encoding='utf-8') | |
| source_code = HtmlFile.read() | |
| components.html(source_code, height = 900,width=900) | |
| got.got_func(physics) | |
| if option=='GOT': | |
| HtmlFile = open("gameofthrones.html", 'r', encoding='utf-8') | |
| source_code = HtmlFile.read() | |
| components.html(source_code, height = 1200,width=1000) | |
| got.karate_func(physics) | |
| if option=='Karate': | |
| HtmlFile = open("karate.html", 'r', encoding='utf-8') | |
| source_code = HtmlFile.read() | |
| components.html(source_code, height = 1200,width=1000) |