Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,28 +4,25 @@ import openai
|
|
| 4 |
# Access the OpenAI API key from environment variables or secrets
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
-
st.title("
|
| 8 |
|
| 9 |
# User inputs
|
| 10 |
-
st.subheader("
|
| 11 |
age = st.number_input("Your Age", min_value=18, max_value=100, step=1)
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
st.subheader("
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
st.
|
| 20 |
-
neighborhood_preferences = st.multiselect("Select Your Neighborhood Preferences", ["Safe", "Family-friendly", "Vibrant nightlife", "Quiet", "Pet-friendly", "Close to nature", "Urban"])
|
| 21 |
-
commute_preference = st.selectbox("Preferred Commute Time", ["Less than 15 minutes", "15-30 minutes", "30-60 minutes", "More than an hour"])
|
| 22 |
-
|
| 23 |
-
if st.button('Find My Ideal Neighborhood'):
|
| 24 |
# Construct the prompt for the AI
|
| 25 |
prompt_text = (
|
| 26 |
-
f"
|
| 27 |
-
f"
|
| 28 |
-
f"
|
| 29 |
)
|
| 30 |
|
| 31 |
# Call the OpenAI API for text generation
|
|
@@ -33,17 +30,17 @@ if st.button('Find My Ideal Neighborhood'):
|
|
| 33 |
response_text = openai.ChatCompletion.create(
|
| 34 |
model="gpt-4",
|
| 35 |
messages=[
|
| 36 |
-
{"role": "system", "content": "You are an AI specializing in
|
| 37 |
{"role": "user", "content": prompt_text}
|
| 38 |
]
|
| 39 |
)
|
| 40 |
-
|
| 41 |
except Exception as e:
|
| 42 |
-
|
| 43 |
|
| 44 |
-
# Display the
|
| 45 |
-
st.markdown("### Your
|
| 46 |
-
st.write(
|
| 47 |
|
| 48 |
# Disclaimer
|
| 49 |
-
st.write("Disclaimer: This tool provides suggestions based on AI-generated content. Please ensure to conduct your own research or consult with a
|
|
|
|
| 4 |
# Access the OpenAI API key from environment variables or secrets
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
+
st.title("Plan Your Investment Strategy")
|
| 8 |
|
| 9 |
# User inputs
|
| 10 |
+
st.subheader("Investment Profile")
|
| 11 |
age = st.number_input("Your Age", min_value=18, max_value=100, step=1)
|
| 12 |
+
investment_experience = st.selectbox("Your Investment Experience", ["Beginner", "Intermediate", "Advanced"])
|
| 13 |
+
investment_goal = st.text_input("Investment Goal", placeholder="e.g., Retirement, Buying a Home, Education")
|
| 14 |
|
| 15 |
+
st.subheader("Financial Information")
|
| 16 |
+
annual_income = st.number_input("Annual Income", min_value=10000, max_value=1000000, step=1000, format="$%i")
|
| 17 |
+
investment_amount = st.number_input("Amount Available for Investment", min_value=1000, max_value=500000, step=100, format="$%i")
|
| 18 |
+
risk_tolerance = st.selectbox("Risk Tolerance", ["Low", "Medium", "High"])
|
| 19 |
|
| 20 |
+
if st.button('Generate My Investment Strategy'):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Construct the prompt for the AI
|
| 22 |
prompt_text = (
|
| 23 |
+
f"Generate an investment strategy for a {age}-year-old with {investment_experience} experience. "
|
| 24 |
+
f"Investment goal: {investment_goal}. Annual income: {annual_income}. "
|
| 25 |
+
f"Amount available for investment: {investment_amount}. Risk tolerance: {risk_tolerance}."
|
| 26 |
)
|
| 27 |
|
| 28 |
# Call the OpenAI API for text generation
|
|
|
|
| 30 |
response_text = openai.ChatCompletion.create(
|
| 31 |
model="gpt-4",
|
| 32 |
messages=[
|
| 33 |
+
{"role": "system", "content": "You are an AI specializing in personalized investment strategies."},
|
| 34 |
{"role": "user", "content": prompt_text}
|
| 35 |
]
|
| 36 |
)
|
| 37 |
+
investment_strategy = response_text.choices[0].message['content']
|
| 38 |
except Exception as e:
|
| 39 |
+
investment_strategy = f"Error in generating investment strategy: {e}"
|
| 40 |
|
| 41 |
+
# Display the investment strategy
|
| 42 |
+
st.markdown("### Your Personalized Investment Strategy")
|
| 43 |
+
st.write(investment_strategy)
|
| 44 |
|
| 45 |
# Disclaimer
|
| 46 |
+
st.write("Disclaimer: This tool provides suggestions based on AI-generated content. Please ensure to conduct your own research or consult with a financial advisor before making any investment decisions.")
|