Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,50 @@
|
|
| 1 |
-
import openai
|
| 2 |
-
import streamlit as st
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
st.session_state
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
with st.chat_message("
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
st.title("GeniusHairBot2.0")
|
| 5 |
+
|
| 6 |
+
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 7 |
+
|
| 8 |
+
grounding = """
|
| 9 |
+
Start by greeting them kindly. Next, ask what their main frustrations are with their hair and which areas they'd like to improve.\
|
| 10 |
+
Frizz: caused by lack of moisture or humidity. Suggest a hydrating serum or leave-in conditioner like Moroccanoil Frizz Control.\
|
| 11 |
+
Dryness: When hair feels brittle, often due to a lack of natural moisture. Recommend deep conditioning treatments like SheaMoisture Intensive Hydration Hair Masque and sulfate-free shampoos.\
|
| 12 |
+
Split Ends/Breakage: Suggest regular trims and Olaplex No.7 Bonding Oil to repair and strengthen hair. For breakage, recommend Aphogee Two-Step Protein Treatment to rebuild damaged hair.\
|
| 13 |
+
Thinning/Loss: Hair thinning can be due to genetics or stress. Recommend Nioxin System Kit to stimulate scalp and support hair growth.Oily Hair: Excess oil production leads to greasy hair. Neutrogena Anti-Residue Shampoo can help clarify without overstimulating oil glands. \
|
| 14 |
+
Dandruff: For flaky scalps, suggest Head & Shoulders Clinical Strength Shampoo to relieve itching and irritation.Tangles: The Wet Brush Detangler works wonders for tangled hair without causing damage.\
|
| 15 |
+
Heat Damage: TRESemmé Thermal Creations Heat Tamer Spray protects from heat up to 450°F, reducing brittleness.Volume: For flat hair, Living Proof Full Dry Volume Blast adds instant texture and fullness.\
|
| 16 |
+
Shrinkage: Camille Rose Curl Maker elongates and defines curls for a natural, stretched look.\
|
| 17 |
+
Lastly, thank them for asking for advice, and wish them luck on their hair health journey! ( do not answer questions unrelated to hair)\
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
if "openai_model" not in st.session_state:
|
| 21 |
+
st.session_state["openai_model"] = "gpt-4o-mini"
|
| 22 |
+
|
| 23 |
+
if "messages" not in st.session_state:
|
| 24 |
+
st.session_state.messages = []
|
| 25 |
+
|
| 26 |
+
for message in st.session_state.messages:
|
| 27 |
+
with st.chat_message(message["role"]):
|
| 28 |
+
st.markdown(message["content"])
|
| 29 |
+
|
| 30 |
+
if prompt := st.chat_input("How can I help you today?"):
|
| 31 |
+
st.session_state.messages.append({"role": "system", "content": grounding})
|
| 32 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 33 |
+
with st.chat_message("user"):
|
| 34 |
+
st.markdown(prompt)
|
| 35 |
+
|
| 36 |
+
with st.chat_message("assistant"):
|
| 37 |
+
message_placeholder = st.empty()
|
| 38 |
+
full_response = ""
|
| 39 |
+
for response in openai.ChatCompletion.create(
|
| 40 |
+
model=st.session_state["openai_model"],
|
| 41 |
+
messages=[
|
| 42 |
+
{"role": m["role"], "content": m["content"]}
|
| 43 |
+
for m in st.session_state.messages
|
| 44 |
+
],
|
| 45 |
+
stream=True,
|
| 46 |
+
):
|
| 47 |
+
full_response += response.choices[0].delta.get("content", "")
|
| 48 |
+
message_placeholder.markdown(full_response + "▌")
|
| 49 |
+
message_placeholder.markdown(full_response)
|
| 50 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|