nniehaus commited on
Commit
68833e7
·
verified ·
1 Parent(s): 3bab3d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -38
app.py CHANGED
@@ -1,41 +1,82 @@
1
  import streamlit as st
2
  import openai
 
 
 
3
 
4
- def main():
5
- st.title("Blog Post Idea and Outline Generator")
6
-
7
- openai.api_key = st.secrets["OPENAI_API_KEY"]
8
-
9
- blog_topic = st.text_input("Enter your blog topic:", value="", placeholder="e.g., Artificial Intelligence in Healthcare")
10
- target_audience = st.text_input("Describe your target audience:", value="", placeholder="e.g., healthcare professionals")
11
- post_length = st.selectbox("Choose the length of your blog post:", ['Short (500 words)', 'Medium (1000 words)', 'Long (1500+ words)'])
12
-
13
- if st.button('Generate Blog Post Ideas and Outlines'):
14
- response = generate_blog_ideas_and_outlines(blog_topic, target_audience, post_length)
15
- if response:
16
- st.subheader("Suggested Blog Post Ideas and Outlines:")
17
- st.write(response)
18
- else:
19
- st.error("Failed to generate blog post ideas and outlines. Please check the inputs and try again.")
20
-
21
- def generate_blog_ideas_and_outlines(topic, audience, length):
22
- try:
23
- prompt_text = f"""As an expert content strategist and writer, create 5 unique blog post ideas on the topic of {topic} for {audience}. For each idea, provide a brief outline suitable for a {length} post. Each outline should include:
24
- 1. An attention-grabbing title
25
- 2. 3-5 main sections with brief descriptions
26
- 3. A concluding thought or call-to-action
27
-
28
- Ensure that each idea is distinct and tailored to the interests and needs of the target audience."""
29
-
30
- response = openai.ChatCompletion.create(
31
- model="gpt-4",
32
- messages=[{"role": "system", "content": prompt_text}],
33
- max_tokens=1000
34
- )
35
- return response.choices[0].message['content']
36
- except Exception as e:
37
- st.error(f"An error occurred: {str(e)}")
38
- return None
39
-
40
- if __name__ == "__main__":
41
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import openai
3
+ import os
4
+ import folium
5
+ from streamlit_folium import st_folium
6
 
7
+ # Ensure your OpenAI API key is set in your environment variables
8
+ openai.api_key = os.environ["OPENAI_API_KEY"]
9
+
10
+ initial_messages = [{
11
+ "role": "system",
12
+ "content": """
13
+ You are a neighborhood matchmaker. Given a person's preferences in terms of amenities, lifestyle, and priorities, suggest three neighborhoods that best match their needs. Provide a short description for each neighborhood, including key features such as nearby amenities, atmosphere, and suitability for the user's preferences.
14
+ """
15
+ }]
16
+
17
+ def call_openai_api(messages):
18
+ return openai.ChatCompletion.create(
19
+ model="gpt-3.5-turbo",
20
+ messages=messages
21
+ )
22
+
23
+ def CustomChatGPT(preferences, messages):
24
+ query = f"User preferences: {preferences}. Suggest suitable neighborhoods."
25
+ messages.append({"role": "user", "content": query})
26
+ response = call_openai_api(messages)
27
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
28
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
29
+ return ChatGPT_reply, messages
30
+
31
+ # Set layout to wide
32
+ st.set_page_config(layout="wide")
33
+
34
+ # Centered title
35
+ st.markdown("<h1 style='text-align: center; color: black;'>Neighborhood Matchmaker</h1>", unsafe_allow_html=True)
36
+
37
+ # Create columns for input and output
38
+ col1, col2 = st.columns(2)
39
+
40
+ with col1:
41
+ st.markdown("<h2 style='text-align: center; color: black;'>Your Preferences</h2>", unsafe_allow_html=True)
42
+ preferences = st.text_area("Describe your ideal neighborhood", placeholder="E.g., family-friendly, good schools, near parks, vibrant nightlife, public transportation, etc.")
43
+ generate_button = st.button('Find Neighborhoods')
44
+
45
+ with col2:
46
+ st.markdown("<h2 style='text-align: center; color: black;'>Recommended Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
47
+ if generate_button:
48
+ messages = initial_messages.copy()
49
+ reply, _ = CustomChatGPT(preferences, messages)
50
+ st.write(reply)
51
+
52
+ # Add map integration
53
+ st.markdown("<h2 style='text-align: center; color: black;'>Map of Suggested Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
54
+ map_center = [37.7749, -122.4194] # Default to San Francisco coordinates
55
+ m = folium.Map(location=map_center, zoom_start=12)
56
+
57
+ # Placeholder coordinates for neighborhoods (these should be updated with actual data)
58
+ neighborhoods = [
59
+ {"name": "Neighborhood 1", "coordinates": [37.7749, -122.4194]},
60
+ {"name": "Neighborhood 2", "coordinates": [37.7849, -122.4094]},
61
+ {"name": "Neighborhood 3", "coordinates": [37.7649, -122.4294]}
62
+ ]
63
+
64
+ for neighborhood in neighborhoods:
65
+ folium.Marker(
66
+ location=neighborhood["coordinates"],
67
+ popup=neighborhood["name"],
68
+ icon=folium.Icon(color='blue')
69
+ ).add_to(m)
70
+
71
+ st_folium(m, width=700, height=500)
72
+
73
+ # Contact capture form
74
+ st.markdown("<h2 style='text-align: center; color: black;'>Get in Touch for More Details ⬇️</h2>", unsafe_allow_html=True)
75
+ with st.form(key='contact_form'):
76
+ name = st.text_input("Your Name", placeholder="Enter your name")
77
+ email = st.text_input("Your Email", placeholder="Enter your email address")
78
+ message = st.text_area("Your Message", placeholder="Let us know how we can assist you further")
79
+ submit_button = st.form_submit_button(label='Submit')
80
+
81
+ if submit_button:
82
+ st.success("Thank you for getting in touch! We'll get back to you shortly.")