import streamlit as st import pandas as pd import numpy as np import tensorflow as tf # Dummy TensorFlow model for demonstration purposes def create_model(): model = tf.keras.Sequential([ tf.keras.layers.Dense(8, activation='relu', input_shape=(4,)), tf.keras.layers.Dense(4, activation='relu'), tf.keras.layers.Dense(1, activation='sigmoid') ]) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) return model model = create_model() # Function to get user preferences def get_user_preferences(): preferences = { "age": st.sidebar.number_input("Age", min_value=0, max_value=120, value=30), "gender": st.sidebar.selectbox("Gender", options=["Male", "Female", "Other"]), "hobbies": st.sidebar.multiselect("Hobbies", options=["Sports", "Reading", "Travel", "Cooking", "Gaming"]), "occupation": st.sidebar.selectbox("Occupation", options=["Student", "Employed", "Unemployed", "Retired"]) } return preferences # Function to preprocess user preferences for TensorFlow model def preprocess_user_preferences(preferences): # Preprocess the user data as needed for your specific model user_data = np.array([preferences['age'], len(preferences['hobbies']), int(preferences['gender'] == "Male"), int(preferences['occupation'] == "Employed")]) return user_data.reshape(1, -1) # Main app def main(): st.title("AI-driven Personalized Experience") st.write("## User Preferences") preferences = get_user_preferences() st.write(preferences) user_data = preprocess_user_preferences(preferences) prediction = model.predict(user_data) st.write("## AI-driven Personalized Content") st.markdown("### Recommendation Score") st.write(f"{prediction[0][0] * 100:.2f}%") st.markdown("### Recommended Activities") activities = pd.DataFrame([ {"Activity": "Outdoor Adventure", "Score": np.random.rand()}, {"Activity": "Book Club", "Score": np.random.rand()}, {"Activity": "Cooking Class", "Score": np.random.rand()}, {"Activity": "Gaming Tournament", "Score": np.random.rand()} ]) activities["Score"] = activities["Score"].apply(lambda x: f"{x * 100:.2f}%") st.table(activities) if __name__ == "__main__": main()