Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from langsmith import LangsmithClient
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
api_key = st.secrets["
|
| 6 |
-
client = LangsmithClient(api_key)
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
max_tokens=150
|
| 15 |
)
|
| 16 |
-
return response
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
with st.form("
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
if
|
| 23 |
-
if
|
| 24 |
-
|
| 25 |
-
st.write("**
|
| 26 |
-
st.write(
|
| 27 |
else:
|
| 28 |
-
st.error("Please
|
| 29 |
|
| 30 |
|
| 31 |
|
|
|
|
| 1 |
+
import openai
|
| 2 |
import streamlit as st
|
|
|
|
| 3 |
|
| 4 |
+
# Set your OpenAI API key
|
| 5 |
+
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
|
|
|
| 6 |
|
| 7 |
+
def generate_personalized_recommendation(user_input, user_preferences):
|
| 8 |
+
prompt = (
|
| 9 |
+
f"Based on the user's input: \"{user_input}\" and their preferences: \"{user_preferences}\", "
|
| 10 |
+
"provide a personalized recommendation. Make sure the recommendation is tailored to the user's interests and needs."
|
| 11 |
+
)
|
| 12 |
+
response = openai.Completion.create(
|
| 13 |
+
engine="gpt-4", # Use the appropriate model
|
| 14 |
+
prompt=prompt,
|
| 15 |
max_tokens=150
|
| 16 |
)
|
| 17 |
+
return response.choices[0].text.strip()
|
| 18 |
+
|
| 19 |
+
# Streamlit app for user interaction
|
| 20 |
+
st.title("Personalized Recommendation System")
|
| 21 |
|
| 22 |
+
with st.form("recommendation_form"):
|
| 23 |
+
user_input = st.text_area("Describe what you're looking for:")
|
| 24 |
+
user_preferences = st.text_input("Share your preferences or interests:")
|
| 25 |
+
submit_button = st.form_submit_button("Get Recommendation")
|
| 26 |
|
| 27 |
+
if submit_button:
|
| 28 |
+
if user_input and user_preferences:
|
| 29 |
+
recommendation = generate_personalized_recommendation(user_input, user_preferences)
|
| 30 |
+
st.write("**Personalized Recommendation:**")
|
| 31 |
+
st.write(recommendation)
|
| 32 |
else:
|
| 33 |
+
st.error("Please provide both your request and preferences.")
|
| 34 |
|
| 35 |
|
| 36 |
|