File size: 1,101 Bytes
4b0a67f |
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 |
import os
from collections import Counter
import streamlit as st
import pandas as pd
# Streamlit app title
# st.title('Tag Frequency Table')
# File uploader to select folder
folder_path = "/home/caimera-prod/Paid-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.table(tag_data)
|