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": """You are an AI assistant that helps users find the perfect engagement ring for their fiance. You'll gather information about their budget, metal preference, carat size, job of the fiance, and whether they prefer a simple or elaborate design. Provide recommendations for engagement rings that match these criteria."""}] def call_openai_api(messages): return openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages ) def CustomChatGPT(user_input, messages): messages.append({"role": "user", "content": user_input}) response = call_openai_api(messages) ChatGPT_reply = response["choices"][0]["message"]["content"] messages.append({"role": "assistant", "content": ChatGPT_reply}) return ChatGPT_reply, messages st.title("Engagement Ring Finder") st.write("This tool helps you find the perfect engagement ring for your fiance. Enter your budget, preferred metal, desired carat size, the job of your fiance, and whether you're looking for something simple or elaborate.") budget = st.text_input("Budget", placeholder="Enter your budget for the ring.") metal_preference = st.text_input("Metal Preference", placeholder="Enter your preferred metal (e.g., gold, platinum).") carat_size = st.text_input("Carat Size", placeholder="Enter the desired carat size.") fiance_job = st.text_input("Fiance's Job", placeholder="Enter your fiance's job (e.g., teacher, engineer).") design_preference = st.selectbox("Design Preference", ["Simple", "Elaborate"]) submit_button = st.button('Find Rings') if submit_button: messages = initial_messages.copy() user_input = f"My budget for the engagement ring is {budget}. I prefer {metal_preference} as the metal. I am looking for a ring with a carat size of {carat_size}. My fiance's job is {fiance_job} and I'm looking for a {design_preference.lower()} design." reply, _ = CustomChatGPT(user_input, messages) st.write(reply)