Spaces:
Sleeping
Sleeping
Commit ·
1066eaf
0
Parent(s):
Initial commit with clean history
Browse files- .gitattributes +35 -0
- .gitignore +4 -0
- README.md +13 -0
- app.py +47 -0
- pages/1_spendings.py +71 -0
- pages/2_Visio.py +21 -0
- requirements.txt +5 -0
- src/__pycache__/functions.cpython-311.pyc +0 -0
- src/functions.py +32 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
venv/
|
| 3 |
+
/venv
|
| 4 |
+
/venv/
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Money IMP
|
| 3 |
+
emoji: 👀
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.42.2
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import streamlit_authenticator as stauth
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
admin_email = os.getenv("ADMIN_EMAIL")
|
| 6 |
+
admin_pass = os.getenv("ADMIN_PASS")
|
| 7 |
+
admin_username = os.getenv("ADMIN_USERNAME")
|
| 8 |
+
cookie_signature_key = os.getenv("COOKIE_SIGNATURE_KEY")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
credentials = {
|
| 12 |
+
'usernames': {
|
| 13 |
+
'impreccable': {
|
| 14 |
+
'email': admin_email,
|
| 15 |
+
'name': admin_username,
|
| 16 |
+
'password': admin_pass
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
cookie_config = {
|
| 22 |
+
'name': 'some_cookie_name',
|
| 23 |
+
'key': cookie_signature_key,
|
| 24 |
+
'expiry_days': 30
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
authenticator = stauth.Authenticate(
|
| 28 |
+
credentials,
|
| 29 |
+
cookie_config['name'],
|
| 30 |
+
cookie_config['key'],
|
| 31 |
+
cookie_config['expiry_days']
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
authenticator.login()
|
| 36 |
+
|
| 37 |
+
if st.session_state['authentication_status']:
|
| 38 |
+
st.session_state['logged_in'] = True
|
| 39 |
+
authenticator.logout()
|
| 40 |
+
st.write(f'Welcome *{st.session_state["name"]}*')
|
| 41 |
+
st.title('Some content')
|
| 42 |
+
elif st.session_state['authentication_status'] is False:
|
| 43 |
+
st.error('Username/password is incorrect')
|
| 44 |
+
elif st.session_state['authentication_status'] is None:
|
| 45 |
+
st.warning('Please enter your username and password')
|
| 46 |
+
except KeyError:
|
| 47 |
+
st.error('Please check your configuration file')
|
pages/1_spendings.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from src.functions import mongodb_connection, get_keys_from_collection, get_from_collection, delete_from_collection
|
| 3 |
+
import datetime
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
tab1, tab2, tab3 = st.tabs(['Add spendings', 'Delete spendings', 'All spendings'])
|
| 7 |
+
|
| 8 |
+
#will be replaced with functions 'GET' from the database
|
| 9 |
+
categories = ['Food', 'Clothing', 'For home', 'Games', 'Health', 'Transport', 'Sport']
|
| 10 |
+
agents = ['Intermatche', 'TAG', 'Steam', 'Uniqlo', 'Action']
|
| 11 |
+
|
| 12 |
+
if st.session_state['authentication_status'] and st.session_state['logged_in']:
|
| 13 |
+
|
| 14 |
+
if mongodb_connection('MoneyIMP', 'spendings')[0]:
|
| 15 |
+
_, collection = mongodb_connection('main', 'spendings')
|
| 16 |
+
#keys = get_keys_from_collection(collection)
|
| 17 |
+
|
| 18 |
+
tab1.write('# Add spendings')
|
| 19 |
+
form = {
|
| 20 |
+
'Date': tab1.date_input('Date').strftime('%d/%m/%Y'),
|
| 21 |
+
'Category': tab1.selectbox('Category:', [''] + categories + ['Other']), #get_from_collection(collection, "Category")
|
| 22 |
+
'Agent': tab1.selectbox('Agent', [''] + agents + ['Other']), #get_from_collection(collection, "Agent")
|
| 23 |
+
'Price': float(tab1.number_input('Price', format='%f')),
|
| 24 |
+
'Notes': tab1.text_input('Notes'),
|
| 25 |
+
'Currency': tab1.selectbox('Currency', ['EUR', 'RUB', 'USD']),
|
| 26 |
+
'Time': datetime.datetime.now().strftime('%H:%M'),
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if form['Category'] == 'Other':
|
| 31 |
+
form['Category'] = tab1.text_input('Enter your custom category:')
|
| 32 |
+
if form['Agent'] == 'Other':
|
| 33 |
+
form['Agent'] = tab1.text_input('Enter your custom agent:')
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
##debugging
|
| 37 |
+
# tab1.write(form)
|
| 38 |
+
|
| 39 |
+
if tab1.button('Submit'):
|
| 40 |
+
collection.insert_one(form)
|
| 41 |
+
tab1.success('Data successfully added to the database.')
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
tab2.write('# Delete spendings')
|
| 45 |
+
data = list(collection.find())
|
| 46 |
+
df = pd.DataFrame(data)
|
| 47 |
+
tab2.dataframe(df)
|
| 48 |
+
|
| 49 |
+
id_to_delete = tab2.selectbox('Enter the ID of the spending you want to delete:', df['_id'])
|
| 50 |
+
if tab2.button('Delete'):
|
| 51 |
+
delete_from_collection(collection, id_to_delete) # Call the delete function
|
| 52 |
+
tab2.success('Data successfully deleted from the database.')
|
| 53 |
+
|
| 54 |
+
# Fetch the updated data and display it
|
| 55 |
+
updated_data = list(collection.find())
|
| 56 |
+
updated_df = pd.DataFrame(updated_data)
|
| 57 |
+
tab2.dataframe(updated_df) # Update the table with new data
|
| 58 |
+
|
| 59 |
+
tab3.write('## All spendings')
|
| 60 |
+
|
| 61 |
+
data = list(collection.find())
|
| 62 |
+
df = pd.DataFrame(data)
|
| 63 |
+
|
| 64 |
+
if '_id' in df.columns:
|
| 65 |
+
df.drop(columns='_id', inplace=True)
|
| 66 |
+
tab3.dataframe(df)
|
| 67 |
+
|
| 68 |
+
else:
|
| 69 |
+
st.write('Please login to view this page.')
|
| 70 |
+
else:
|
| 71 |
+
st.write('Please login to view this page.')
|
pages/2_Visio.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from src.functions import mongodb_connection
|
| 4 |
+
|
| 5 |
+
st.write('# Visio ')
|
| 6 |
+
|
| 7 |
+
if st.session_state['authentication_status']:
|
| 8 |
+
st.write('## All spendings')
|
| 9 |
+
# if mongodb_connection('MoneyIMP', 'spendings')[0]:
|
| 10 |
+
# _, collection = mongodb_connection('main', 'spendings')
|
| 11 |
+
|
| 12 |
+
# # Retrieve all data from the collection
|
| 13 |
+
# data = list(collection.find())
|
| 14 |
+
# df = pd.DataFrame(data)
|
| 15 |
+
|
| 16 |
+
# if '_id' in df.columns:
|
| 17 |
+
# df.drop(columns='_id', inplace=True)
|
| 18 |
+
# df = st.dataframe(df)
|
| 19 |
+
|
| 20 |
+
else:
|
| 21 |
+
st.write('Please login to view this page.')
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pymongo[srv]
|
| 3 |
+
pandas
|
| 4 |
+
streamlit-authenticator
|
| 5 |
+
watchdog
|
src/__pycache__/functions.cpython-311.pyc
ADDED
|
Binary file (2.08 kB). View file
|
|
|
src/functions.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo.mongo_client import MongoClient
|
| 2 |
+
from pymongo.server_api import ServerApi
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
URI_OS = os.getenv("MONGODB_LOGIN")
|
| 8 |
+
|
| 9 |
+
def mongodb_connection(db_name: str, collection_name: str) -> tuple:
|
| 10 |
+
client = MongoClient(URI_OS, server_api=ServerApi('1'))
|
| 11 |
+
db = client[db_name]
|
| 12 |
+
collection = db[collection_name]
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
client.admin.command('ping')
|
| 16 |
+
print("MongoDB connection successful")
|
| 17 |
+
return True, collection
|
| 18 |
+
except Exception as e:
|
| 19 |
+
print(f"Error: {e}")
|
| 20 |
+
return False, None
|
| 21 |
+
|
| 22 |
+
def get_keys_from_collection(collection) -> list:
|
| 23 |
+
document = collection.find_one()
|
| 24 |
+
return document.keys()
|
| 25 |
+
|
| 26 |
+
def get_from_collection(collection, name: str) -> list:
|
| 27 |
+
categories = collection.distinct(name)
|
| 28 |
+
return categories
|
| 29 |
+
|
| 30 |
+
def delete_from_collection(collection, id_to_delete: str) -> None:
|
| 31 |
+
collection.delete_one({'_id': id_to_delete})
|
| 32 |
+
return None
|