Show a plot
Browse files- app.py +56 -4
- encodings_2.csv +0 -2
app.py
CHANGED
|
@@ -1,9 +1,61 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
columns=["a", "b", "c"])
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import plotly.express as px
|
| 5 |
|
| 6 |
+
# Set the page configuration to wide layout
|
| 7 |
+
st.set_page_config(layout="wide")
|
|
|
|
| 8 |
|
| 9 |
+
data = pd.read_csv("encodings_2.csv")
|
| 10 |
+
|
| 11 |
+
# Select only the 'token' and 'count' columns
|
| 12 |
+
token_count_data = data[['token', 'count']]
|
| 13 |
+
|
| 14 |
+
# Set the 'token' column as the index
|
| 15 |
+
token_count_data = token_count_data.set_index('token')
|
| 16 |
+
|
| 17 |
+
# Sort the data by 'count' in descending order
|
| 18 |
+
token_count_data = token_count_data.sort_values('count', ascending=False)
|
| 19 |
+
|
| 20 |
+
# Add sliders with floating-point values
|
| 21 |
+
slider1 = st.slider('Select lower percentage', min_value=0.0,
|
| 22 |
+
max_value=100.0, value=0.0, step=0.1)
|
| 23 |
+
slider2 = st.slider('Select upper percentage', min_value=0.0,
|
| 24 |
+
max_value=100.0, value=1.0, step=0.1)
|
| 25 |
+
|
| 26 |
+
if slider1 > slider2:
|
| 27 |
+
st.warning(
|
| 28 |
+
"Lower percentage should be less than or equal to upper percentage.")
|
| 29 |
+
else:
|
| 30 |
+
# Calculate the number of rows to display based on the selected percentage range
|
| 31 |
+
total_rows = len(token_count_data)
|
| 32 |
+
lower_index = int(total_rows * slider1 / 100)
|
| 33 |
+
upper_index = int(total_rows * slider2 / 100)
|
| 34 |
+
|
| 35 |
+
# Filter the data based on the selected range and sort by 'count' in ascending order
|
| 36 |
+
filtered_data = token_count_data.iloc[lower_index:upper_index].sort_values(
|
| 37 |
+
'count', ascending=True)
|
| 38 |
+
|
| 39 |
+
# Create a bar chart using Plotly with all labels
|
| 40 |
+
fig = px.bar(filtered_data, x='count',
|
| 41 |
+
y=filtered_data.index, text=filtered_data.index)
|
| 42 |
+
fig.update_yaxes(type='category', tickmode='array',
|
| 43 |
+
tickvals=filtered_data.index)
|
| 44 |
+
fig.update_layout(height=5000)
|
| 45 |
+
|
| 46 |
+
# Display the bar chart using Streamlit
|
| 47 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 48 |
+
|
| 49 |
+
# Set the chart width to a percentage of the container width
|
| 50 |
+
width_percentage = 90
|
| 51 |
+
html_code = f"""
|
| 52 |
+
<script>
|
| 53 |
+
document.addEventListener("DOMContentLoaded", function() {{
|
| 54 |
+
var chart = document.getElementsByClassName('js-plotly-plot')[0];
|
| 55 |
+
if (chart) {{
|
| 56 |
+
chart.style.width = '{width_percentage}%';
|
| 57 |
+
}}
|
| 58 |
+
}});
|
| 59 |
+
</script>
|
| 60 |
+
"""
|
| 61 |
+
st.markdown(html_code, unsafe_allow_html=True)
|
encodings_2.csv
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
index,count,token
|
| 2 |
-
49406,512446141,<|startoftext|>
|
| 3 |
2423,53313,victor
|
| 4 |
22698,49071,inox
|
| 5 |
1711,123951,spec
|
|
@@ -11,7 +10,6 @@ index,count,token
|
|
| 11 |
10382,110000,expand
|
| 12 |
863,1624373,able
|
| 13 |
29924,138157,spinner
|
| 14 |
-
49407,512446141,<|endoftext|>
|
| 15 |
5853,925296,makeup
|
| 16 |
21550,120228,brushes
|
| 17 |
268,250036789,-
|
|
|
|
| 1 |
index,count,token
|
|
|
|
| 2 |
2423,53313,victor
|
| 3 |
22698,49071,inox
|
| 4 |
1711,123951,spec
|
|
|
|
| 10 |
10382,110000,expand
|
| 11 |
863,1624373,able
|
| 12 |
29924,138157,spinner
|
|
|
|
| 13 |
5853,925296,makeup
|
| 14 |
21550,120228,brushes
|
| 15 |
268,250036789,-
|