Spaces:
Runtime error
Runtime error
import streamlit as st | |
import streamlit_authenticator as stauth | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from wordcloud import WordCloud | |
import sqlite3 | |
conn = sqlite3.connect('data.db') | |
c = conn.cursor() | |
def create_usertable(): | |
c.execute('CREATE TABLE IF NOT EXISTS userstable(username TEXT,password TEXT)') | |
def add_userdata(username,password): | |
c.execute('INSERT INTO userstable(username,password) VALUES (?,?)',(username,password)) | |
conn.commit() | |
def login_user(username,password): | |
c.execute('SELECT * FROM userstable WHERE username =? AND password = ?',(username,password)) | |
data = c.fetchall() | |
return data | |
def view_all_users(): | |
c.execute('SELECT * FROM userstable') | |
data = c.fetchall() | |
return data | |
url = "https://cdn.pixabay.com/photo/2022/02/25/09/23/background-7033808_1280.jpg" | |
st.image(url) | |
a = st.sidebar.radio("SELECT -", ['HOME', 'Login', 'SignUp']) | |
if a == 'HOME' : | |
st.title("Word Cloud Generator πΆβπ«οΈ") | |
st.write("Follow steps -") | |
st.write("1. Signup") | |
st.write("2. Login") | |
st.write("3. Select word cloud from tasks") | |
st.write("4. Congratulations!") | |
elif a == 'Login' : | |
st.title("Welecome Back... Login") | |
username = st.text_input("User Name") | |
password = st.text_input("Password",type='password') | |
if st.checkbox("Login"): | |
#if password == 'mlh2023' : | |
create_usertable() | |
result = login_user(username,password) | |
if result: | |
st.success("logged in as {}".format(username)) | |
task = st.selectbox("Task",['Word Cloud','Post your thoughts', 'Profiles']) | |
if task == 'Word Cloud': | |
st.subheader("This is Word Cloud Generator") | |
text = st.text_input("Your Text") | |
if st.button('Confirm!'): | |
st.write('Confirmed') | |
word_cloud = WordCloud(collocations = False, background_color = 'white').generate(text) | |
fig, ax = plt.subplots(figsize = (12, 8)) | |
plt.imshow(word_cloud, interpolation='bilinear') | |
plt.axis("off") | |
plt.show() | |
st.pyplot(fig) | |
else : | |
st.write('') | |
elif task == 'Post your thoughts': | |
st.subheader("Thankyou for your Support") | |
elif task == 'Profiles': | |
st.subheader("Users profiles") | |
user_result = view_all_users() | |
clean_db = pd.DataFrame(user_result,columns=["Username","Password"]) | |
st.dataframe(clean_db) | |
else: | |
st.warning("Incorrect Password") | |
elif a == 'SignUp' : | |
st.title("Welecome New User") | |
st.subheader("Create New Account") | |
new_user = st.text_input("Username") | |
new_password = st.text_input("Password",type='password') | |
if st.button("SignUp"): | |
create_usertable() | |
add_userdata(new_user,new_password) | |
st.success("Great! welecome to my secure app") | |
st.info("Go to Login Menu to login") |