nniehaus commited on
Commit
263f4b6
·
verified ·
1 Parent(s): 6e2adf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -58
app.py CHANGED
@@ -1,65 +1,44 @@
1
  import streamlit as st
2
  import openai
3
- import os
4
 
5
  # Ensure your OpenAI API key is set in your environment variables
6
- openai.api_key = os.environ["OPENAI_API_KEY"]
7
 
8
- initial_messages = [{
9
- "role": "system",
10
- "content": """
11
- You are an assistant that helps people plan their first YouTube video. Your suggestions should be geared toward creating engaging content that matches the user's expertise, personality, and interests. Provide a structured plan including:
12
- - Video Topic
13
- - Suggested Title
14
- - Video Outline (main points or segments)
15
- - Hook/Opening Line
16
- - Recommended Call to Action
17
- """
18
- }]
19
-
20
- def call_openai_api(messages):
21
- return openai.ChatCompletion.create(
22
  model="gpt-3.5-turbo",
23
- messages=messages
 
24
  )
25
-
26
- def CustomChatGPT(user_input, messages):
27
- query = f"User's expertise and interests: {user_input}. Suggest a structured plan for their first YouTube video."
28
- messages.append({"role": "user", "content": query})
29
- response = call_openai_api(messages)
30
- ChatGPT_reply = response["choices"][0]["message"]["content"]
31
- messages.append({"role": "assistant", "content": ChatGPT_reply})
32
- return ChatGPT_reply, messages
33
-
34
- # Set layout to wide
35
- st.set_page_config(layout="wide")
36
-
37
- # Centered title
38
- st.markdown("<h1 style='text-align: center; color: black;'>YouTube Video Planner</h1>", unsafe_allow_html=True)
39
-
40
- # Create columns for input and output
41
- col1, col2 = st.columns(2)
42
-
43
- with col1:
44
- st.markdown("<h2 style='text-align: center; color: black;'>Your Expertise & Interests</h2>", unsafe_allow_html=True)
45
- user_input = st.text_area("Describe your expertise and interests", placeholder="E.g., cooking, fitness, real estate, technology, travel, etc.")
46
- generate_button = st.button('Generate Video Plan')
47
-
48
- if generate_button:
49
- messages = initial_messages.copy()
50
- reply, _ = CustomChatGPT(user_input, messages)
51
-
52
- with col2:
53
- st.markdown("<h2 style='text-align: center; color: black;'>Your YouTube Video Plan ⬇️</h2>", unsafe_allow_html=True)
54
- st.write(reply)
55
-
56
- # Contact capture form
57
- st.markdown("<h2 style='text-align: center; color: black;'>Get in Touch for More Help ⬇️</h2>", unsafe_allow_html=True)
58
- with st.form(key='contact_form'):
59
- name = st.text_input("Your Name", placeholder="Enter your name")
60
- email = st.text_input("Your Email", placeholder="Enter your email address")
61
- message = st.text_area("Your Message", placeholder="Let us know how we can assist you further")
62
- submit_button = st.form_submit_button(label='Submit')
63
-
64
- if submit_button:
65
- st.success("Thank you for getting in touch! We'll get back to you shortly.")
 
1
  import streamlit as st
2
  import openai
3
+ import urllib.parse
4
 
5
  # Ensure your OpenAI API key is set in your environment variables
6
+ openai.api_key = 'your_openai_api_key'
7
 
8
+ # Function to get neighborhood suggestions from OpenAI
9
+ def suggest_neighborhoods(user_preferences, city=""):
10
+ prompt = (f"Based on the following preferences, suggest neighborhoods in {city}: {user_preferences}. "
11
+ "For each neighborhood, provide a brief description including its main attractions and why it would suit these preferences.")
12
+ response = openai.Completion.create(
 
 
 
 
 
 
 
 
 
13
  model="gpt-3.5-turbo",
14
+ prompt=prompt,
15
+ max_tokens=150
16
  )
17
+ return response.choices[0].text.strip()
18
+
19
+ # Function to generate Zillow search link for a neighborhood
20
+ def generate_zillow_link(neighborhood):
21
+ neighborhood_query = urllib.parse.quote(neighborhood)
22
+ return f"https://www.zillow.com/homes/{neighborhood_query}_rb/"
23
+
24
+ # Streamlit Interface
25
+ st.title("Ideal Neighborhood Finder")
26
+ st.write("Describe what you're looking for in an ideal neighborhood, and we'll suggest neighborhoods with Zillow links for homes in those areas.")
27
+
28
+ # User Inputs
29
+ city = st.text_input("City", placeholder="Enter the city you want to search in")
30
+ user_preferences = st.text_area("Describe Your Ideal Neighborhood", placeholder="E.g., close to schools, parks, public transit, vibrant nightlife, etc.")
31
+
32
+ if st.button("Find Neighborhoods"):
33
+ if city and user_preferences:
34
+ # Get neighborhood suggestions from OpenAI
35
+ neighborhoods = suggest_neighborhoods(user_preferences, city)
36
+
37
+ # Display results
38
+ st.subheader("Neighborhood Suggestions")
39
+ for neighborhood in neighborhoods.splitlines():
40
+ if neighborhood: # Filter out empty lines
41
+ zillow_link = generate_zillow_link(neighborhood)
42
+ st.markdown(f"- **{neighborhood}**: [View homes on Zillow]({zillow_link})")
43
+ else:
44
+ st.error("Please provide both a city and a description of your ideal neighborhood.")