Yoonc commited on
Commit
1ba9117
·
verified ·
1 Parent(s): a40f71c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +258 -7
app.py CHANGED
@@ -8,7 +8,7 @@ import json
8
  import os
9
  import warnings
10
  from dotenv import load_dotenv
11
- import together # Updated import
12
 
13
  warnings.filterwarnings("ignore")
14
  load_dotenv()
@@ -26,12 +26,164 @@ client = together if TOGETHER_API_KEY else None
26
 
27
  # Assessment Questions
28
  QUESTIONS = [
29
- # ... keep all your questions exactly as before ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ]
31
 
32
  # Religion Descriptions
33
  RELIGIONS = {
34
- # ... keep all your religions exactly as before ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
  def load_users():
@@ -62,8 +214,107 @@ def calculate_results(answers):
62
  recommendations.append(religion_info)
63
  return recommendations
64
 
65
- # --- Flask routes (login, signup, home, logout, assessment routes) ---
66
- # Keep all your existing routes unchanged
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  @app.route("/chat", methods=["POST"])
69
  def chat():
@@ -109,7 +360,7 @@ Rules: Keep 30-50 words, be respectful, use * for bullet points (format: "Text:
109
  temperature=0.7,
110
  )
111
 
112
- bot_response = response.output[0].content[0].text # ✅ Correctly indented
113
  return jsonify({
114
  "success": True,
115
  "response": bot_response
@@ -122,4 +373,4 @@ Rules: Keep 30-50 words, be respectful, use * for bullet points (format: "Text:
122
  })
123
 
124
  if __name__ == "__main__":
125
- app.run(debug=True, port=5001)
 
8
  import os
9
  import warnings
10
  from dotenv import load_dotenv
11
+ import together
12
 
13
  warnings.filterwarnings("ignore")
14
  load_dotenv()
 
26
 
27
  # Assessment Questions
28
  QUESTIONS = [
29
+ {
30
+ "id": 1,
31
+ "question": "What is your view on the existence of God or a higher power?",
32
+ "options": {
33
+ "One supreme God": {"Christianity": 3, "Islam": 3, "Judaism": 3, "Sikhism": 3},
34
+ "Multiple gods": {"Hinduism": 3, "Ancient Greek": 3, "Norse": 3},
35
+ "Spiritual force/energy": {"Buddhism": 2, "Taoism": 3, "New Age": 3},
36
+ "Uncertain/Agnostic": {"Secular Humanism": 3, "Buddhism": 1},
37
+ "No God (Atheist)": {"Secular Humanism": 3}
38
+ }
39
+ },
40
+ {
41
+ "id": 2,
42
+ "question": "How do you prefer to connect with the divine or spiritual realm?",
43
+ "options": {
44
+ "Organized worship services": {"Christianity": 3, "Islam": 3, "Judaism": 3},
45
+ "Personal meditation": {"Buddhism": 3, "Hinduism": 2, "New Age": 2},
46
+ "Nature and environment": {"Taoism": 3, "Wicca": 3, "Indigenous": 3},
47
+ "Study and reflection": {"Judaism": 2, "Secular Humanism": 3},
48
+ "No spiritual practice": {"Secular Humanism": 3}
49
+ }
50
+ },
51
+ {
52
+ "id": 3,
53
+ "question": "What role should religious texts play in your life?",
54
+ "options": {
55
+ "Central authority": {"Islam": 3, "Christianity": 3, "Judaism": 3},
56
+ "Guidance but not absolute": {"Hinduism": 2, "Buddhism": 2, "Sikhism": 2},
57
+ "Philosophical insights": {"Taoism": 2, "Buddhism": 2, "Confucianism": 3},
58
+ "Not important": {"Secular Humanism": 3, "New Age": 1}
59
+ }
60
+ },
61
+ {
62
+ "id": 4,
63
+ "question": "What happens after death?",
64
+ "options": {
65
+ "Heaven or Hell": {"Christianity": 3, "Islam": 3},
66
+ "Reincarnation": {"Hinduism": 3, "Buddhism": 3, "Sikhism": 2},
67
+ "Merge with the universe": {"Taoism": 3, "New Age": 2},
68
+ "Nothing/End of consciousness": {"Secular Humanism": 3},
69
+ "Unknown": {"Secular Humanism": 1, "Buddhism": 1}
70
+ }
71
+ },
72
+ {
73
+ "id": 5,
74
+ "question": "How important is community in your spiritual life?",
75
+ "options": {
76
+ "Very important": {"Christianity": 3, "Islam": 3, "Judaism": 3, "Sikhism": 3},
77
+ "Somewhat important": {"Hinduism": 2, "Buddhism": 2, "Wicca": 2},
78
+ "Not very important": {"Taoism": 2, "New Age": 2},
79
+ "Prefer solitary practice": {"Buddhism": 1, "New Age": 2}
80
+ }
81
+ },
82
+ {
83
+ "id": 6,
84
+ "question": "What is the purpose of life?",
85
+ "options": {
86
+ "Serve God": {"Christianity": 3, "Islam": 3, "Judaism": 3},
87
+ "Achieve enlightenment": {"Buddhism": 3, "Hinduism": 3},
88
+ "Live in harmony": {"Taoism": 3, "Confucianism": 3, "Indigenous": 3},
89
+ "Help humanity": {"Secular Humanism": 3, "Sikhism": 2},
90
+ "Personal fulfillment": {"New Age": 3, "Secular Humanism": 2}
91
+ }
92
+ },
93
+ {
94
+ "id": 7,
95
+ "question": "How do you view suffering?",
96
+ "options": {
97
+ "Test from God": {"Christianity": 3, "Islam": 3, "Judaism": 2},
98
+ "Result of attachment": {"Buddhism": 3},
99
+ "Natural part of life": {"Taoism": 3, "Stoicism": 3, "Secular Humanism": 2},
100
+ "Karma from past actions": {"Hinduism": 3, "Buddhism": 2, "Sikhism": 2}
101
+ }
102
+ },
103
+ {
104
+ "id": 8,
105
+ "question": "What is your stance on ritual and ceremony?",
106
+ "options": {
107
+ "Essential": {"Hinduism": 3, "Judaism": 3, "Wicca": 3},
108
+ "Important but flexible": {"Christianity": 2, "Islam": 2, "Buddhism": 2},
109
+ "Optional": {"New Age": 2, "Taoism": 2},
110
+ "Unnecessary": {"Secular Humanism": 3}
111
+ }
112
+ }
113
  ]
114
 
115
  # Religion Descriptions
116
  RELIGIONS = {
117
+ "Christianity": {
118
+ "name": "Christianity",
119
+ "description": "Based on the life and teachings of Jesus Christ, emphasizing love, forgiveness, and salvation through faith.",
120
+ "core_beliefs": "Trinity (Father, Son, Holy Spirit), Salvation through Jesus, Bible as sacred text",
121
+ "practices": "Church attendance, prayer, sacraments, Bible study",
122
+ "resources": ["Bible", "Local churches", "Christian counseling", "Bible.com"]
123
+ },
124
+ "Islam": {
125
+ "name": "Islam",
126
+ "description": "Monotheistic faith revealed to Prophet Muhammad, emphasizing submission to Allah's will.",
127
+ "core_beliefs": "Five Pillars, Quran as final revelation, Prophet Muhammad, One God (Allah)",
128
+ "practices": "Five daily prayers, fasting during Ramadan, charity, pilgrimage to Mecca",
129
+ "resources": ["Quran", "Local mosques", "Islamic centers", "Quran.com"]
130
+ },
131
+ "Buddhism": {
132
+ "name": "Buddhism",
133
+ "description": "Path to enlightenment through understanding the nature of suffering and following the Eightfold Path.",
134
+ "core_beliefs": "Four Noble Truths, Eightfold Path, Karma, Reincarnation, No eternal soul",
135
+ "practices": "Meditation, mindfulness, following precepts, studying dharma",
136
+ "resources": ["Buddhist temples", "Meditation centers", "AccessToInsight.org"]
137
+ },
138
+ "Hinduism": {
139
+ "name": "Hinduism",
140
+ "description": "Ancient tradition with diverse beliefs, emphasizing dharma, karma, and moksha (liberation).",
141
+ "core_beliefs": "Brahman (ultimate reality), Karma, Reincarnation, Multiple paths to divine",
142
+ "practices": "Puja (worship), yoga, meditation, festivals, pilgrimages",
143
+ "resources": ["Bhagavad Gita", "Hindu temples", "Yoga centers"]
144
+ },
145
+ "Judaism": {
146
+ "name": "Judaism",
147
+ "description": "Covenant relationship between God and the Jewish people, emphasizing Torah study and ethical living.",
148
+ "core_beliefs": "One God, Chosen people, Torah, Messiah to come, Ethical monotheism",
149
+ "practices": "Sabbath observance, kashrut (dietary laws), prayer, Torah study",
150
+ "resources": ["Torah", "Synagogues", "Jewish community centers"]
151
+ },
152
+ "Sikhism": {
153
+ "name": "Sikhism",
154
+ "description": "Monotheistic faith founded by Guru Nanak, emphasizing equality, service, and devotion to one God.",
155
+ "core_beliefs": "One God, Equality of all people, Karma and reincarnation, Guru Granth Sahib",
156
+ "practices": "Prayer, meditation on God's name, service (seva), honest living",
157
+ "resources": ["Guru Granth Sahib", "Gurdwaras", "Sikh community organizations"]
158
+ },
159
+ "Taoism": {
160
+ "name": "Taoism",
161
+ "description": "Chinese philosophy emphasizing living in harmony with the Tao (the Way), natural flow of the universe.",
162
+ "core_beliefs": "The Tao, Wu wei (effortless action), Yin and yang, Natural harmony",
163
+ "practices": "Meditation, Tai Chi, Qigong, simplicity, nature connection",
164
+ "resources": ["Tao Te Ching", "Taoist temples", "Tai Chi classes"]
165
+ },
166
+ "Secular Humanism": {
167
+ "name": "Secular Humanism",
168
+ "description": "Non-religious philosophy emphasizing reason, ethics, human welfare without supernatural beliefs.",
169
+ "core_beliefs": "Human reason, Scientific method, Ethical living without religion, Human dignity",
170
+ "practices": "Critical thinking, ethical action, community service, rational inquiry",
171
+ "resources": ["Humanist organizations", "Secular communities", "Philosophy books"]
172
+ },
173
+ "New Age": {
174
+ "name": "New Age Spirituality",
175
+ "description": "Modern spiritual movement combining various traditions, emphasizing personal growth and consciousness.",
176
+ "core_beliefs": "Universal energy, Personal transformation, Interconnectedness, Alternative healing",
177
+ "practices": "Meditation, crystal healing, astrology, energy work, holistic wellness",
178
+ "resources": ["Spiritual centers", "Wellness workshops", "Metaphysical bookstores"]
179
+ },
180
+ "Wicca": {
181
+ "name": "Wicca",
182
+ "description": "Modern pagan religion honoring nature, practicing ritual magic, and worshipping the Goddess and God.",
183
+ "core_beliefs": "Nature reverence, Magic, Goddess and God, Harm none, Wheel of the Year",
184
+ "practices": "Seasonal rituals, spell work, moon celebrations, nature worship",
185
+ "resources": ["Wiccan covens", "Pagan gatherings", "Nature-based spirituality books"]
186
+ }
187
  }
188
 
189
  def load_users():
 
214
  recommendations.append(religion_info)
215
  return recommendations
216
 
217
+ # Routes
218
+ @app.route("/")
219
+ def index():
220
+ if 'username' in session:
221
+ return redirect(url_for('home'))
222
+ return render_template("login.html")
223
+
224
+ @app.route("/signup")
225
+ def signup_page():
226
+ return render_template("signup.html")
227
+
228
+ @app.route("/home")
229
+ def home():
230
+ if 'username' not in session:
231
+ return redirect(url_for('index'))
232
+ users = load_users()
233
+ user_data = users.get(session['username'], {})
234
+ return render_template("home.html", username=session['username'], user_data=user_data)
235
+
236
+ @app.route("/assessment")
237
+ def assessment():
238
+ if 'username' not in session:
239
+ return redirect(url_for('index'))
240
+ return render_template("assessment.html", questions=QUESTIONS)
241
+
242
+ @app.route("/results")
243
+ def results():
244
+ if 'username' not in session:
245
+ return redirect(url_for('index'))
246
+ users = load_users()
247
+ user_data = users.get(session['username'], {})
248
+ recommendations = user_data.get('recommendations', [])
249
+ return render_template("results.html", recommendations=recommendations)
250
+
251
+ @app.route("/login", methods=["POST"])
252
+ def login():
253
+ data = request.json
254
+ username = data.get('username', '').strip()
255
+ password = data.get('password', '').strip()
256
+
257
+ if not username or not password:
258
+ return jsonify({"success": False, "message": "Username and password required"})
259
+
260
+ users = load_users()
261
+ if username in users and users[username].get('password') == password:
262
+ session['username'] = username
263
+ return jsonify({"success": True, "message": "Login successful"})
264
+
265
+ return jsonify({"success": False, "message": "Invalid credentials"})
266
+
267
+ @app.route("/signup_submit", methods=["POST"])
268
+ def signup_submit():
269
+ data = request.json
270
+ username = data.get('username', '').strip()
271
+ email = data.get('email', '').strip()
272
+ password = data.get('password', '').strip()
273
+
274
+ if not username or not email or not password:
275
+ return jsonify({"success": False, "message": "All fields required"})
276
+
277
+ users = load_users()
278
+ if username in users:
279
+ return jsonify({"success": False, "message": "Username already exists"})
280
+
281
+ users[username] = {
282
+ "email": email,
283
+ "password": password,
284
+ "answers": [],
285
+ "recommendations": []
286
+ }
287
+ save_users(users)
288
+ session['username'] = username
289
+ return jsonify({"success": True, "message": "Account created successfully"})
290
+
291
+ @app.route("/submit_assessment", methods=["POST"])
292
+ def submit_assessment():
293
+ if 'username' not in session:
294
+ return jsonify({"success": False, "message": "Not logged in"})
295
+
296
+ data = request.json
297
+ answers = data.get('answers', [])
298
+
299
+ if not answers:
300
+ return jsonify({"success": False, "message": "No answers provided"})
301
+
302
+ users = load_users()
303
+ username = session['username']
304
+
305
+ if username in users:
306
+ users[username]['answers'] = answers
307
+ recommendations = calculate_results(answers)
308
+ users[username]['recommendations'] = recommendations
309
+ save_users(users)
310
+ return jsonify({"success": True, "recommendations": recommendations})
311
+
312
+ return jsonify({"success": False, "message": "User not found"})
313
+
314
+ @app.route("/logout")
315
+ def logout():
316
+ session.pop('username', None)
317
+ return redirect(url_for('index'))
318
 
319
  @app.route("/chat", methods=["POST"])
320
  def chat():
 
360
  temperature=0.7,
361
  )
362
 
363
+ bot_response = response.output[0].content[0].text
364
  return jsonify({
365
  "success": True,
366
  "response": bot_response
 
373
  })
374
 
375
  if __name__ == "__main__":
376
+ app.run(debug=True, host="0.0.0.0", port=7860)