Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import sqlite3 | |
| import pandas as pd | |
| # Connect to the database | |
| conn = sqlite3.connect('users.db') | |
| c = conn.cursor() | |
| # Create a function to retrieve user prompts from the database | |
| def get_user_prompts(username=None): | |
| if username: | |
| c.execute('SELECT * FROM user_prompts WHERE username=?', (username,)) | |
| else: | |
| c.execute('SELECT * FROM user_prompts') | |
| user_prompts = c.fetchall() | |
| return user_prompts | |
| # Create a function to convert user prompts to a Pandas DataFrame | |
| def user_prompts_to_df(user_prompts): | |
| df = pd.DataFrame(user_prompts, columns=['id', 'username', 'prompt_time', 'prompt_type']) | |
| return df | |
| # Create a Streamlit page | |
| st.title("User Prompts Summary") | |
| # Retrieve all usernames from the database | |
| c.execute('SELECT username FROM userstable') | |
| usernames = [row[0] for row in c.fetchall()] | |
| # Add a selectbox to filter user prompts by username | |
| username_filter = st.selectbox("Filter by username", ["All"] + usernames) | |
| # Retrieve user prompts based on the selected username | |
| if username_filter == "All": | |
| user_prompts = get_user_prompts() | |
| else: | |
| user_prompts = get_user_prompts(username_filter) | |
| # Convert user prompts to a Pandas DataFrame | |
| df = user_prompts_to_df(user_prompts) | |
| # Display the DataFrame | |
| st.write(df) |