File size: 1,156 Bytes
40091d2 |
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 35 36 37 38 39 40 41 42 43 44 45 |
import streamlit as st
import sqlite3
import pandas as pd
# Initialize SQLite database
conn = sqlite3.connect('word_classification.db')
c = conn.cursor()
# Create table if it doesn't exist
c.execute('''
CREATE TABLE IF NOT EXISTS word_classification (
word TEXT,
category TEXT
)
''')
# Function to save word and its category
def save_word(word, category):
c.execute("INSERT INTO word_classification (word, category) VALUES (?, ?)",
(word, category))
conn.commit()
# Function to load words
def load_words():
df = pd.read_sql_query("SELECT * FROM word_classification", conn)
return df
# Streamlit UI
st.title('Word Classification')
# Input fields for word and category
word = st.text_input('Enter Word')
category = st.selectbox('Select Category', ['Theme', 'Subtheme', 'Keywords'])
if st.button('Save Word'):
save_word(word, category)
st.success(f'Word "{word}" saved under category "{category}"!')
if st.button('View All Entries'):
df = load_words()
st.dataframe(df)
# Close the database connection when the app is done
conn.close()
|