Spaces:
Runtime error
Runtime error
Create backupapp.py
Browse files- backupapp.py +62 -0
backupapp.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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():
|
8 |
+
model = tf.keras.Sequential([
|
9 |
+
tf.keras.layers.Dense(8, activation='relu', input_shape=(4,)),
|
10 |
+
tf.keras.layers.Dense(4, activation='relu'),
|
11 |
+
tf.keras.layers.Dense(1, activation='sigmoid')
|
12 |
+
])
|
13 |
+
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
|
14 |
+
return model
|
15 |
+
|
16 |
+
model = create_model()
|
17 |
+
|
18 |
+
# Function to get user preferences
|
19 |
+
def get_user_preferences():
|
20 |
+
preferences = {
|
21 |
+
"age": st.sidebar.number_input("Age", min_value=0, max_value=120, value=30),
|
22 |
+
"gender": st.sidebar.selectbox("Gender", options=["Male", "Female", "Other"]),
|
23 |
+
"hobbies": st.sidebar.multiselect("Hobbies", options=["Sports", "Reading", "Travel", "Cooking", "Gaming"]),
|
24 |
+
"occupation": st.sidebar.selectbox("Occupation", options=["Student", "Employed", "Unemployed", "Retired"])
|
25 |
+
}
|
26 |
+
return preferences
|
27 |
+
|
28 |
+
# Function to preprocess user preferences for TensorFlow model
|
29 |
+
def preprocess_user_preferences(preferences):
|
30 |
+
# Preprocess the user data as needed for your specific model
|
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)
|
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}%")
|
49 |
+
|
50 |
+
st.markdown("### Recommended Activities")
|
51 |
+
activities = pd.DataFrame([
|
52 |
+
{"Activity": "Outdoor Adventure", "Score": np.random.rand()},
|
53 |
+
{"Activity": "Book Club", "Score": np.random.rand()},
|
54 |
+
{"Activity": "Cooking Class", "Score": np.random.rand()},
|
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()
|