Spaces:
Runtime error
Runtime error
Update backupapp.py
Browse files- backupapp.py +30 -3
backupapp.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,18 +33,41 @@ 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
43 |
prediction = model.predict(user_data)
|
44 |
|
45 |
st.write("## AI-driven Personalized Content")
|
|
|
46 |
|
47 |
st.markdown("### Recommendation Score")
|
48 |
st.write(f"{prediction[0][0] * 100:.2f}%")
|
@@ -55,8 +80,10 @@ 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 |
|
61 |
if __name__ == "__main__":
|
62 |
-
main()
|
|
|
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 |
def main():
|
52 |
st.title("AI-driven Personalized Experience")
|
|
|
53 |
|
54 |
preferences = get_user_preferences()
|
55 |
+
|
56 |
+
if "username" in preferences and preferences["username"]:
|
57 |
+
loaded_preferences = load_user_preferences(preferences["username"])
|
58 |
+
if loaded_preferences:
|
59 |
+
preferences.update(loaded_preferences)
|
60 |
+
else:
|
61 |
+
save_user_preferences(preferences)
|
62 |
+
|
63 |
+
st.write("## User Preferences")
|
64 |
st.write(preferences)
|
65 |
|
66 |
user_data = preprocess_user_preferences(preferences)
|
67 |
prediction = model.predict(user_data)
|
68 |
|
69 |
st.write("## AI-driven Personalized Content")
|
70 |
+
|
71 |
|
72 |
st.markdown("### Recommendation Score")
|
73 |
st.write(f"{prediction[0][0] * 100:.2f}%")
|
|
|
80 |
{"Activity": "Gaming Tournament", "Score": np.random.rand()}
|
81 |
])
|
82 |
|
83 |
+
# Sort activities by score in descending order and take the top 10
|
84 |
+
activities = activities.sort_values(by="Score", ascending=False).head(10)
|
85 |
activities["Score"] = activities["Score"].apply(lambda x: f"{x * 100:.2f}%")
|
86 |
st.table(activities)
|
87 |
|
88 |
if __name__ == "__main__":
|
89 |
+
main()
|