Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import openai
|
|
6 |
from flask import Flask
|
7 |
|
8 |
# Streamlit Configuration
|
9 |
-
st.set_page_config(page_title="
|
10 |
|
11 |
# Flask Configuration for Database and Mail
|
12 |
app = Flask(__name__)
|
@@ -16,11 +16,11 @@ db = SQLAlchemy(app)
|
|
16 |
bcrypt = Bcrypt(app)
|
17 |
|
18 |
# Configuring Flask-Mail
|
19 |
-
app.config['MAIL_SERVER'] = 'smtp.
|
20 |
-
app.config['MAIL_PORT'] =
|
21 |
app.config['MAIL_USERNAME'] = '[email protected]'
|
22 |
-
app.config['MAIL_PASSWORD'] = ''
|
23 |
-
app.config['MAIL_USE_TLS'] =
|
24 |
app.config['MAIL_USE_SSL'] = False
|
25 |
mail = Mail(app)
|
26 |
|
@@ -53,7 +53,19 @@ class Collaborator(db.Model):
|
|
53 |
|
54 |
# Streamlit Pages
|
55 |
st.sidebar.title("Navigation")
|
56 |
-
page = st.sidebar.radio("Go to", ["Register", "Login", "Dashboard", "Create Issue", "Invite Collaborators", "Submit Solution", "Decide"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# Register Page
|
59 |
def register():
|
@@ -68,9 +80,8 @@ def register():
|
|
68 |
new_user = User(username=username, email=email, password=hashed_pw)
|
69 |
db.session.add(new_user)
|
70 |
db.session.commit()
|
71 |
-
|
72 |
st.success("Registration successful! Please check your email for further instructions.")
|
73 |
-
|
74 |
# Send registration email
|
75 |
msg = Message('Welcome to Sociocracy App', sender='[email protected]', recipients=[email])
|
76 |
msg.body = "Thank you for registering. You can now log in and start collaborating."
|
@@ -100,8 +111,10 @@ def dashboard():
|
|
100 |
|
101 |
st.title("Dashboard")
|
102 |
user_id = st.session_state['user_id']
|
103 |
-
|
104 |
with app.app_context():
|
|
|
|
|
|
|
105 |
user_issues = Issue.query.filter_by(created_by=user_id).all()
|
106 |
collaboration_issues = Issue.query.join(Collaborator).filter(Collaborator.user_id == user_id).all()
|
107 |
|
@@ -191,16 +204,16 @@ def decide(issue_id):
|
|
191 |
st.write(f"- {solution.content}")
|
192 |
|
193 |
if st.button("Get AI Decision"):
|
194 |
-
openai.api_key =
|
195 |
-
prompt = f"Given the following solutions for the issue '{issue.title}', which one is the most socio-democratic decision
|
196 |
for solution in solutions:
|
197 |
prompt += f"- {solution.content}\n"
|
198 |
-
prompt += "Please consider socio-democratic values and provide a summary on the best decision.
|
199 |
|
200 |
response = openai.ChatCompletion.create(
|
201 |
model="gpt-3.5-turbo",
|
202 |
messages=[
|
203 |
-
{"role": "system", "content": "You are an assistant helping to make socio-democratic decisions.
|
204 |
{"role": "user", "content": prompt}
|
205 |
],
|
206 |
max_tokens=150
|
@@ -208,7 +221,17 @@ def decide(issue_id):
|
|
208 |
decision = response.choices[0].message['content'].strip()
|
209 |
st.write(f"AI Decision: {decision}")
|
210 |
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
if 'user_id' not in st.session_state:
|
213 |
st.session_state['user_id'] = None
|
214 |
|
@@ -227,4 +250,6 @@ elif page == "Submit Solution":
|
|
227 |
submit_solution(issue_id)
|
228 |
elif page == "Decide":
|
229 |
issue_id = st.number_input("Issue ID", min_value=1, step=1)
|
230 |
-
decide(issue_id)
|
|
|
|
|
|
6 |
from flask import Flask
|
7 |
|
8 |
# Streamlit Configuration
|
9 |
+
st.set_page_config(page_title="Sociocracy App")
|
10 |
|
11 |
# Flask Configuration for Database and Mail
|
12 |
app = Flask(__name__)
|
|
|
16 |
bcrypt = Bcrypt(app)
|
17 |
|
18 |
# Configuring Flask-Mail
|
19 |
+
app.config['MAIL_SERVER'] = 'smtp.example.com'
|
20 |
+
app.config['MAIL_PORT'] = 587
|
21 |
app.config['MAIL_USERNAME'] = '[email protected]'
|
22 |
+
app.config['MAIL_PASSWORD'] = 'your_password'
|
23 |
+
app.config['MAIL_USE_TLS'] = True
|
24 |
app.config['MAIL_USE_SSL'] = False
|
25 |
mail = Mail(app)
|
26 |
|
|
|
53 |
|
54 |
# Streamlit Pages
|
55 |
st.sidebar.title("Navigation")
|
56 |
+
page = st.sidebar.radio("Go to", ["Register", "Login", "Dashboard", "Create Issue", "Invite Collaborators", "Submit Solution", "Decide", "Settings"])
|
57 |
+
|
58 |
+
# Header for Notifications and User Info
|
59 |
+
if 'user_id' in st.session_state and st.session_state['user_id'] is not None:
|
60 |
+
with app.app_context():
|
61 |
+
user = User.query.get(st.session_state['user_id'])
|
62 |
+
if user:
|
63 |
+
st.sidebar.markdown(f"**Hello, {user.username}**")
|
64 |
+
notification_icon = "🔔"
|
65 |
+
if Issue.query.join(Collaborator).filter(Collaborator.user_id == user.id).count() > 0:
|
66 |
+
notification_icon = "🔔 (New)"
|
67 |
+
st.sidebar.write(f"[{notification_icon} Notifications](#)")
|
68 |
+
st.sidebar.write("[⚙️ Settings](#)")
|
69 |
|
70 |
# Register Page
|
71 |
def register():
|
|
|
80 |
new_user = User(username=username, email=email, password=hashed_pw)
|
81 |
db.session.add(new_user)
|
82 |
db.session.commit()
|
|
|
83 |
st.success("Registration successful! Please check your email for further instructions.")
|
84 |
+
|
85 |
# Send registration email
|
86 |
msg = Message('Welcome to Sociocracy App', sender='[email protected]', recipients=[email])
|
87 |
msg.body = "Thank you for registering. You can now log in and start collaborating."
|
|
|
111 |
|
112 |
st.title("Dashboard")
|
113 |
user_id = st.session_state['user_id']
|
|
|
114 |
with app.app_context():
|
115 |
+
user = User.query.get(user_id)
|
116 |
+
st.header(f"Hello, {user.username}")
|
117 |
+
|
118 |
user_issues = Issue.query.filter_by(created_by=user_id).all()
|
119 |
collaboration_issues = Issue.query.join(Collaborator).filter(Collaborator.user_id == user_id).all()
|
120 |
|
|
|
204 |
st.write(f"- {solution.content}")
|
205 |
|
206 |
if st.button("Get AI Decision"):
|
207 |
+
openai.api_key = 'your_openai_api_key'
|
208 |
+
prompt = f"Given the following solutions for the issue '{issue.title}', which one is the most socio-democratic decision?\n"
|
209 |
for solution in solutions:
|
210 |
prompt += f"- {solution.content}\n"
|
211 |
+
prompt += "Please consider socio-democratic values and provide a summary on the best decision."
|
212 |
|
213 |
response = openai.ChatCompletion.create(
|
214 |
model="gpt-3.5-turbo",
|
215 |
messages=[
|
216 |
+
{"role": "system", "content": "You are an assistant helping to make socio-democratic decisions."},
|
217 |
{"role": "user", "content": prompt}
|
218 |
],
|
219 |
max_tokens=150
|
|
|
221 |
decision = response.choices[0].message['content'].strip()
|
222 |
st.write(f"AI Decision: {decision}")
|
223 |
|
224 |
+
# Settings Page
|
225 |
+
def settings():
|
226 |
+
if 'user_id' not in st.session_state:
|
227 |
+
st.warning("You need to log in first.")
|
228 |
+
return
|
229 |
+
|
230 |
+
st.title("Settings")
|
231 |
+
st.write("Update your general information here.")
|
232 |
+
# Add settings fields as needed
|
233 |
+
|
234 |
+
# Main Flow
|
235 |
if 'user_id' not in st.session_state:
|
236 |
st.session_state['user_id'] = None
|
237 |
|
|
|
250 |
submit_solution(issue_id)
|
251 |
elif page == "Decide":
|
252 |
issue_id = st.number_input("Issue ID", min_value=1, step=1)
|
253 |
+
decide(issue_id)
|
254 |
+
elif page == "Settings":
|
255 |
+
settings()
|