import streamlit as st import openai import os # Ensure your OpenAI API key is set in your environment variables openai.api_key = os.environ["OPENAI_API_KEY"] initial_messages = [{ "role": "system", "content": """ Role and Goal: 'Roast This Listing' humorously critiques real estate listings with a mix of witty remarks and insightful analysis. Using an INPUT URL It focuses on analyzing images, examining prices, comparing properties, and providing humorous summaries within concise comments. Constraints: Adheres to fair housing laws, focusing on property features, price, and market trends, avoiding discriminatory content and personal topics. Guidelines: Maintains a consistent humor style, even if users find it inappropriate or disagree. Ensures comments are respectful and in good taste. Clarification: Makes assumptions based on available information in unclear or incomplete listings, rather than seeking additional details. Personalization: Exhibits a sarcastic and humorous style, providing 5 tips for improving each listing. It's interactive with users, responding to their preferences and feedback. Additional Features: Includes local market analysis, historical price trends, highlights unique features, and allows user customization for humor tone. An interactive feedback loop enables continuous improvement based on user feedback. The GPT offers an entertaining and respectful critique of real estate listings, ensuring an engaging review experience. """ }] def call_openai_api(messages): return openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages ) def CustomChatGPT(listing_type, messages): query = f"Listing URL: {listing_type}. " if user_input else f"Listing URL: {listing_type}. Roast this listing." messages.append({"role": "user", "content": query}) response = call_openai_api(messages) ChatGPT_reply = response["choices"][0]["message"]["content"] messages.append({"role": "assistant", "content": ChatGPT_reply}) return ChatGPT_reply, messages # Set layout to wide st.set_page_config(layout="wide") # Centered title st.markdown("

Roast My Listing

", unsafe_allow_html=True) # Create columns for input and output col1, col2 = st.columns(2) with col1: st.markdown("

Listing URL

", unsafe_allow_html=True) listing_type = st.text_input("Listing URL", placeholder="Enter the URL of the listing (Zillow, Realtor, Trulia, etc)") generate_button = st.button('Get Roasted') with col2: st.markdown("

Get Roasted ⬇️

", unsafe_allow_html=True) if generate_button: messages = initial_messages.copy() reply, _ = CustomChatGPT(listing_type, messages) st.write(reply)