Finetuning_Dataset / plotting_all_keywords_streamlit.py
Anustup's picture
Rename stream_lit_plotly.py to plotting_all_keywords_streamlit.py
7a53e88 verified
raw
history blame
1.47 kB
import os
from collections import Counter
import streamlit as st
import pandas as pd
import plotly.express as px
# Streamlit app title
# st.title('Interactive Tag Frequency Visualization')
# File uploader to select folder
folder_path = "/home/caimera-prod/eye_tagged_data"
if folder_path:
# Initialize a Counter to count tag frequency
tag_counter = Counter()
# Iterate through each .txt file in the folder
for file_name in os.listdir(folder_path):
if file_name.endswith('.txt'):
file_path = os.path.join(folder_path, file_name)
with open(file_path, 'r') as file:
tags = file.read().strip().split(',')
# Clean and count each tag
tags = [tag.strip().lower() for tag in tags]
tag_counter.update(tags)
# Convert the Counter to a DataFrame for better display
tag_data = pd.DataFrame(tag_counter.items(), columns=['Tag', 'Count'])
tag_data = tag_data.sort_values(by='Count', ascending=False).reset_index(drop=True)
# Display the DataFrame as a table in Streamlit
st.subheader('Tag Frequency Table')
st.dataframe(tag_data)
# Create an interactive bar chart using Plotly
st.subheader('Interactive Tag Frequency Bar Chart')
fig = px.bar(tag_data, x='Tag', y='Count', title='Tag Frequency', labels={'Count': 'Frequency'}, height=600)
fig.update_layout(xaxis_title='Tags', yaxis_title='Frequency')
st.plotly_chart(fig)