graceisa414 commited on
Commit
d276a1f
·
verified ·
1 Parent(s): 36760c1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -53
app.py CHANGED
@@ -1,54 +1,53 @@
1
- import openai
2
- import streamlit as st
3
-
4
- st.title("GeniusHairBot")
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
- image = Image.open('logo.png')
21
-
22
- st.image(image)
23
-
24
- if "openai_model" not in st.session_state:
25
- st.session_state["openai_model"] = "gpt-4o-mini"
26
-
27
- if "messages" not in st.session_state:
28
- st.session_state.messages = []
29
-
30
- for message in st.session_state.messages:
31
- with st.chat_message(message["role"]):
32
- st.markdown(message["content"])
33
-
34
- if prompt := st.chat_input("How can I help you today?"):
35
- st.session_state.messages.append({"role": "system", "content": grounding})
36
- st.session_state.messages.append({"role": "user", "content": prompt})
37
- with st.chat_message("user"):
38
- st.markdown(prompt)
39
-
40
- with st.chat_message("assistant"):
41
- message_placeholder = st.empty()
42
- full_response = ""
43
- for response in openai.ChatCompletion.create(
44
- model=st.session_state["openai_model"],
45
- messages=[
46
- {"role": m["role"], "content": m["content"]}
47
- for m in st.session_state.messages
48
- ],
49
- stream=True,
50
- ):
51
- full_response += response.choices[0].delta.get("content", "")
52
- message_placeholder.markdown(full_response + "▌")
53
- message_placeholder.markdown(full_response)
54
  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
+ image = Image.open('logo.png')
20
+
21
+ st.image(image)
22
+
23
+ if "openai_model" not in st.session_state:
24
+ st.session_state["openai_model"] = "gpt-4o-mini"
25
+
26
+ if "messages" not in st.session_state:
27
+ st.session_state.messages = []
28
+
29
+ for message in st.session_state.messages:
30
+ with st.chat_message(message["role"]):
31
+ st.markdown(message["content"])
32
+
33
+ if prompt := st.chat_input("How can I help you today?"):
34
+ st.session_state.messages.append({"role": "system", "content": grounding})
35
+ st.session_state.messages.append({"role": "user", "content": prompt})
36
+ with st.chat_message("user"):
37
+ st.markdown(prompt)
38
+
39
+ with st.chat_message("assistant"):
40
+ message_placeholder = st.empty()
41
+ full_response = ""
42
+ for response in openai.ChatCompletion.create(
43
+ model=st.session_state["openai_model"],
44
+ messages=[
45
+ {"role": m["role"], "content": m["content"]}
46
+ for m in st.session_state.messages
47
+ ],
48
+ stream=True,
49
+ ):
50
+ full_response += response.choices[0].delta.get("content", "")
51
+ message_placeholder.markdown(full_response + "")
52
+ message_placeholder.markdown(full_response)
 
53
  st.session_state.messages.append({"role": "assistant", "content": full_response})