| | import os |
| | from collections import Counter |
| | import streamlit as st |
| | import pandas as pd |
| | import plotly.express as px |
| | from PIL import Image |
| |
|
| | |
| | st.title('Interactive Tag Frequency Visualization') |
| |
|
| | |
| | folder_path = "/home/caimera-prod/eye_tagged_data" |
| |
|
| | if folder_path: |
| | |
| | tag_counter = Counter() |
| | file_resolutions = [] |
| |
|
| | |
| | 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: |
| | content = file.read().strip() |
| | if 'eye' in content.lower(): |
| | tags = content.split(',') |
| | |
| | tags = [tag.strip().lower() for tag in tags] |
| | tag_counter.update(tags) |
| |
|
| | |
| | image_name = file_name.replace('.txt', '.jpg') |
| | image_path = os.path.join(folder_path, image_name) |
| | if os.path.exists(image_path): |
| | image = Image.open(image_path) |
| | resolution = image.size |
| | file_resolutions.append((file_name, resolution[0], resolution[1])) |
| | else: |
| | file_resolutions.append((file_name, 'N/A', 'N/A')) |
| |
|
| | |
| | tag_data = pd.DataFrame(tag_counter.items(), columns=['Tag', 'Count']) |
| | tag_data = tag_data.sort_values(by='Count', ascending=False).reset_index(drop=True) |
| |
|
| | resolution_data = pd.DataFrame(file_resolutions, columns=['File Name', 'Width', 'Height']) |
| |
|
| | |
| | if not tag_data.empty: |
| | st.subheader('Tag Frequency Table') |
| | st.dataframe(tag_data) |
| |
|
| | st.subheader('Image Resolutions for Files Containing "eye"') |
| | st.dataframe(resolution_data) |
| |
|
| | |
| | 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) |
| | else: |
| | st.write("No tags found in files containing the word 'eye'.") |
| |
|