-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedback.py
71 lines (60 loc) · 2.22 KB
/
feedback.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import streamlit as st
import json
from supabase_integration import update_keywords, update_thresholds
from ml_model import retrain_model
from supabase_integration import update_keywords
# Load or initialize thresholds
try:
with open("data/thresholds.json", "r") as f:
RENEWAL_THRESHOLDS = json.load(f)
except FileNotFoundError:
RENEWAL_THRESHOLDS = {
"Daily": 1,
"Weekly": 7,
"Bi-Weekly": 15,
"Monthly": 45,
"Quarterly": 90,
"Yearly": 370,
}
with open("data/keywords.json", "r") as f:
CATEGORY_KEYWORDS = json.load(f)
except FileNotFoundError:
CATEGORY_KEYWORDS = {
"Entertainment": ["Netflix", "Spotify", "Hulu"],
"Utilities": ["Electric", "Water", "Gas"],
"Others": []
}
def adjust_keywords():
"""
Allow users to add new keywords dynamically.
"""
st.title("Adjust Keywords")
category = st.selectbox("Select a category:", ["Entertainment", "Utilities", "Others"])
new_keyword = st.text_input("Enter a new keyword:")
if st.button("Add Keyword"):
update_keywords(category, new_keyword)
st.success(f"Keyword '{new_keyword}' added to category '{category}'!")
def adjust_thresholds():
"""
Allow users to refine thresholds for subscription patterns.
"""
global RENEWAL_THRESHOLDS
st.title("Adjust Renewal Thresholds")
for pattern, threshold in RENEWAL_THRESHOLDS.items():
new_threshold = st.number_input(f"Threshold for {pattern} (days)", value=threshold, min_value=1)
RENEWAL_THRESHOLDS[pattern] = new_threshold
update_thresholds(RENEWAL_THRESHOLDS)
st.success("Thresholds updated!")
def gather_feedback(data):
"""
Gather user feedback and retrain the ML model.
"""
st.title("User Feedback for Categorization")
for index, row in data.iterrows():
new_category = st.text_input(f"Category for {row['Merchant']}:", value=row['Category'])
data.at[index, 'Category'] = new_category
if st.button("Submit Feedback"):
train_model(data, features=['Merchant', 'Description'], target='Category')
update_keywords(data['Category'].unique())
st.success("Feedback submitted and model retrained!")