awacke1 commited on
Commit
88d9353
·
1 Parent(s): 9efb7f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  import pandas as pd
3
  import numpy as np
4
  import tensorflow as tf
 
 
5
 
6
  # Dummy TensorFlow model for demonstration purposes
7
  def create_model():
@@ -31,12 +33,35 @@ def preprocess_user_preferences(preferences):
31
  user_data = np.array([preferences['age'], len(preferences['hobbies']), int(preferences['gender'] == "Male"), int(preferences['occupation'] == "Employed")])
32
  return user_data.reshape(1, -1)
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Main app
35
  def main():
36
  st.title("AI-driven Personalized Experience")
37
- st.write("## User Preferences")
38
 
39
  preferences = get_user_preferences()
 
 
 
 
 
 
 
 
 
40
  st.write(preferences)
41
 
42
  user_data = preprocess_user_preferences(preferences)
@@ -44,6 +69,7 @@ def main():
44
 
45
  st.write("## AI-driven Personalized Content")
46
 
 
47
  st.markdown("### Recommendation Score")
48
  st.write(f"{prediction[0][0] * 100:.2f}%")
49
 
@@ -55,6 +81,8 @@ def main():
55
  {"Activity": "Gaming Tournament", "Score": np.random.rand()}
56
  ])
57
 
 
 
58
  activities["Score"] = activities["Score"].apply(lambda x: f"{x * 100:.2f}%")
59
  st.table(activities)
60
 
 
2
  import pandas as pd
3
  import numpy as np
4
  import tensorflow as tf
5
+ import json
6
+ import os
7
 
8
  # Dummy TensorFlow model for demonstration purposes
9
  def create_model():
 
33
  user_data = np.array([preferences['age'], len(preferences['hobbies']), int(preferences['gender'] == "Male"), int(preferences['occupation'] == "Employed")])
34
  return user_data.reshape(1, -1)
35
 
36
+ # Function to save user preferences to a text file
37
+ def save_user_preferences(preferences):
38
+ file_path = f"{preferences['username']}.txt"
39
+ with open(file_path, 'w') as outfile:
40
+ json.dump(preferences, outfile)
41
+
42
+ # Function to load user preferences from a text file
43
+ def load_user_preferences(username):
44
+ file_path = f"{username}.txt"
45
+ if os.path.exists(file_path):
46
+ with open(file_path, 'r') as infile:
47
+ preferences = json.load(infile)
48
+ return preferences
49
+ return None
50
+
51
  # Main app
52
  def main():
53
  st.title("AI-driven Personalized Experience")
 
54
 
55
  preferences = get_user_preferences()
56
+
57
+ if preferences["username"]:
58
+ loaded_preferences = load_user_preferences(preferences["username"])
59
+ if loaded_preferences:
60
+ preferences = loaded_preferences
61
+ else:
62
+ save_user_preferences(preferences)
63
+
64
+ st.write("## User Preferences")
65
  st.write(preferences)
66
 
67
  user_data = preprocess_user_preferences(preferences)
 
69
 
70
  st.write("## AI-driven Personalized Content")
71
 
72
+
73
  st.markdown("### Recommendation Score")
74
  st.write(f"{prediction[0][0] * 100:.2f}%")
75
 
 
81
  {"Activity": "Gaming Tournament", "Score": np.random.rand()}
82
  ])
83
 
84
+ # Sort activities by score in descending order and take the top 10
85
+ activities = activities.sort_values(by="Score", ascending=False).head(10)
86
  activities["Score"] = activities["Score"].apply(lambda x: f"{x * 100:.2f}%")
87
  st.table(activities)
88