Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,101 +1,137 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
<ul style='color:black;'>
|
| 25 |
-
<li>Use sunscreen daily (SPF 30+)</li>
|
| 26 |
-
<li>Stay hydrated</li>
|
| 27 |
-
<li>Get 7β8 hours of sleep</li>
|
| 28 |
-
</ul>
|
| 29 |
-
|
| 30 |
-
<h3 style='color: red;'>Skincare Tips:</h3>
|
| 31 |
-
<ul style='color:black;'>
|
| 32 |
-
<li>Use Vitamin C serum in the morning</li>
|
| 33 |
-
<li>Apply Niacinamide at night</li>
|
| 34 |
-
<li>Exfoliate 2x a week using AHAs</li>
|
| 35 |
-
</ul>
|
| 36 |
-
|
| 37 |
-
<h3 style='color: red;'>Diet Suggestions:</h3>
|
| 38 |
-
<ul style='color:black;'>
|
| 39 |
-
<li>Eat foods rich in antioxidants (berries, green tea)</li>
|
| 40 |
-
<li>Reduce sugar and dairy intake</li>
|
| 41 |
-
</ul>
|
| 42 |
-
"""
|
| 43 |
-
elif "acne" in concern:
|
| 44 |
-
response += """
|
| 45 |
-
<h3 style='color: red;'>Lifestyle Changes:</h3>
|
| 46 |
-
<ul style='color:black;'>
|
| 47 |
-
<li>Avoid touching your face</li>
|
| 48 |
-
<li>Change pillow covers regularly</li>
|
| 49 |
-
<li>Manage stress with meditation or walks</li>
|
| 50 |
-
</ul>
|
| 51 |
-
|
| 52 |
-
<h3 style='color: red;'>Skincare Tips:</h3>
|
| 53 |
-
<ul style='color:black;'>
|
| 54 |
-
<li>Use a salicylic acid cleanser</li>
|
| 55 |
-
<li>Apply benzoyl peroxide or adapalene</li>
|
| 56 |
-
<li>Donβt skip moisturizer (use non-comedogenic)</li>
|
| 57 |
-
</ul>
|
| 58 |
-
|
| 59 |
-
<h3 style='color: red;'>Diet Suggestions:</h3>
|
| 60 |
-
<ul style='color:black;'>
|
| 61 |
-
<li>Reduce oily and processed foods</li>
|
| 62 |
-
<li>Drink green tea regularly</li>
|
| 63 |
-
</ul>
|
| 64 |
-
"""
|
| 65 |
-
elif "dry skin" in concern:
|
| 66 |
-
response += """
|
| 67 |
-
<h3 style='color: red;'>Lifestyle Changes:</h3>
|
| 68 |
-
<ul style='color:black;'>
|
| 69 |
-
<li>Avoid long hot showers</li>
|
| 70 |
-
<li>Use a humidifier in dry seasons</li>
|
| 71 |
-
</ul>
|
| 72 |
-
|
| 73 |
-
<h3 style='color: red;'>Skincare Tips:</h3>
|
| 74 |
-
<ul style='color:black;'>
|
| 75 |
-
<li>Use a gentle, fragrance-free cleanser</li>
|
| 76 |
-
<li>Apply hyaluronic acid followed by a thick moisturizer</li>
|
| 77 |
-
<li>Use overnight masks weekly</li>
|
| 78 |
-
</ul>
|
| 79 |
-
|
| 80 |
-
<h3 style='color: red;'>Diet Suggestions:</h3>
|
| 81 |
-
<ul style='color:black;'>
|
| 82 |
-
<li>Include omega-3-rich foods like walnuts and flaxseeds</li>
|
| 83 |
-
</ul>
|
| 84 |
-
"""
|
| 85 |
else:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
"""
|
| 92 |
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import os, random
|
| 3 |
+
from groq import Groq
|
| 4 |
|
| 5 |
+
# β
Initialize Groq client
|
| 6 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 7 |
|
| 8 |
+
# β
Improved stickers (cute, health/skincare-related)
|
| 9 |
+
stickers = [
|
| 10 |
+
"https://media.giphy.com/media/3o6Zt481isNVuQI1l6/giphy.gif", # Cream applying
|
| 11 |
+
"https://media.giphy.com/media/l3q2XB76CaWPggiNW/giphy.gif", # Aloe vera
|
| 12 |
+
"https://media.giphy.com/media/26tPplGWjN0xLybiU/giphy.gif", # Water drinking
|
| 13 |
+
"https://media.giphy.com/media/3o7TKP9XDb9IzUrJXa/giphy.gif", # Cucumber eyes
|
| 14 |
+
"https://media.giphy.com/media/26Fxy3Iz1ari8oytO/giphy.gif", # Face mask cute
|
| 15 |
+
]
|
| 16 |
|
| 17 |
+
def skincare_advice(name, gender, age, skin_concern, description, image, duration, sensitivity, routine):
|
| 18 |
+
if not description.strip() and (skin_concern == "Other" or not skin_concern.strip()):
|
| 19 |
+
return "β Please select or describe your skin concern."
|
| 20 |
+
if not name.strip():
|
| 21 |
+
return "β Please enter your name for personalized advice."
|
| 22 |
+
|
| 23 |
+
user_issue = description if description.strip() else skin_concern
|
| 24 |
+
random_factor = random.randint(1, 10000)
|
| 25 |
+
|
| 26 |
+
if gender == "Female":
|
| 27 |
+
gender_pref = "Focus on hydration, mild natural ingredients, and avoid harsh scrubs."
|
| 28 |
+
elif gender == "Male":
|
| 29 |
+
gender_pref = "Men often need oil-control and deep cleansing due to thicker skin."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
else:
|
| 31 |
+
gender_pref = "Use a balanced routine suitable for all skin types."
|
| 32 |
+
|
| 33 |
+
prompt = f"""
|
| 34 |
+
User Profile:
|
| 35 |
+
- Name: {name}
|
| 36 |
+
- Gender: {gender}
|
| 37 |
+
- Age: {age}
|
| 38 |
+
- Skin Concern: {skin_concern}
|
| 39 |
+
- Description: {user_issue}
|
| 40 |
+
- Duration: {duration}
|
| 41 |
+
- Sensitive Skin: {sensitivity}
|
| 42 |
+
- Skincare Routine: {routine}
|
| 43 |
+
|
| 44 |
+
Additional Preference based on Gender:
|
| 45 |
+
{gender_pref}
|
| 46 |
+
|
| 47 |
+
Creativity factor: {random_factor}
|
| 48 |
+
|
| 49 |
+
FORMAT STRICTLY:
|
| 50 |
+
π Personalized Greeting (use Name & friendly tone)
|
| 51 |
+
π©Ί Skin Issue Summary (1 concise line)
|
| 52 |
+
π Global Insight (but vary percentage, not same every time)
|
| 53 |
+
π§΄ Daily Care Routine (3 bullet points)
|
| 54 |
+
πΏ One Natural Remedy (unique each time)
|
| 55 |
+
π‘ 3 Lifestyle Tips (not generic, vary)
|
| 56 |
+
π¬ Motivational Quote (1 line, italic)
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
response = client.chat.completions.create(
|
| 61 |
+
model="llama3-8b-8192",
|
| 62 |
+
messages=[{"role": "user", "content": prompt}]
|
| 63 |
+
)
|
| 64 |
+
result = response.choices[0].message.content.strip()
|
| 65 |
+
except:
|
| 66 |
+
result = f"""
|
| 67 |
+
π Hi {name}, great to see you here!
|
| 68 |
+
π©Ί Your skin concern: {skin_concern}
|
| 69 |
+
π Around {random.randint(10,80)}% of people face this issue globally.
|
| 70 |
+
π§΄ Daily Care Routine:
|
| 71 |
+
β’ Cleanse twice daily with a mild face wash
|
| 72 |
+
β’ Hydrate with light moisturizer
|
| 73 |
+
β’ Apply SPF 30 sunscreen before going out
|
| 74 |
+
πΏ Natural Remedy: Honey + turmeric paste for 10 mins once a week
|
| 75 |
+
π‘ Lifestyle Tips:
|
| 76 |
+
β’ Sleep at least 7 hrs daily
|
| 77 |
+
β’ Eat omega-rich foods (fish, nuts)
|
| 78 |
+
β’ Avoid touching your face frequently
|
| 79 |
+
π¬ *Your skin reflects how kindly you treat yourself.*
|
| 80 |
"""
|
| 81 |
|
| 82 |
+
sticker = random.choice(stickers)
|
| 83 |
|
| 84 |
+
formatted_output = result
|
| 85 |
+
for emoji, title in [
|
| 86 |
+
("π", "Greeting"),
|
| 87 |
+
("π©Ί", "Skin Issue Summary"),
|
| 88 |
+
("π", "Global Insight"),
|
| 89 |
+
("π§΄", "Daily Care Routine"),
|
| 90 |
+
("πΏ", "Natural Remedy"),
|
| 91 |
+
("π‘", "Lifestyle Tips"),
|
| 92 |
+
("π¬", "Quote")
|
| 93 |
+
]:
|
| 94 |
+
formatted_output = formatted_output.replace(
|
| 95 |
+
emoji,
|
| 96 |
+
f"<h4 style='color:red;'>{emoji} {title}</h4><div style='color:black;'>"
|
| 97 |
+
)
|
| 98 |
+
formatted_output += "</div>"
|
| 99 |
+
|
| 100 |
+
return f"""
|
| 101 |
+
<div style='font-family:Arial, sans-serif; color:#111; background:#fff; padding:20px;
|
| 102 |
+
border-radius:15px; border:2px solid #000; box-shadow:0px 3px 10px rgba(0,0,0,0.3);'>
|
| 103 |
+
<div style='display:flex; align-items:center; justify-content:space-between;'>
|
| 104 |
+
<h2 style='color:#000; margin:0;'>π€ <b>{name}</b> | {gender}, {age} yrs</h2>
|
| 105 |
+
<img src="{sticker}" style="width:70px; border-radius:10px;">
|
| 106 |
+
</div>
|
| 107 |
+
<div style='margin-top:15px; font-size:16px; line-height:1.7;'>
|
| 108 |
+
{formatted_output.replace('*', '<b>').replace('', '</b>')}
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
# β
Streamlit App
|
| 114 |
+
st.set_page_config(page_title="SkinSense AI", layout="centered")
|
| 115 |
+
st.markdown("""
|
| 116 |
+
<h1 style='text-align:center; font-family:Arial; font-size:30px;
|
| 117 |
+
background: linear-gradient(to right, black, #4CAF50);
|
| 118 |
+
-webkit-background-clip: text; color: transparent;'>
|
| 119 |
+
πΏ <b>Welcome to SkinSense AI β Your Smart Skincare Buddy</b>
|
| 120 |
+
</h1>
|
| 121 |
+
""", unsafe_allow_html=True)
|
| 122 |
+
|
| 123 |
+
with st.form("skincare_form"):
|
| 124 |
+
name = st.text_input("π Name")
|
| 125 |
+
gender = st.selectbox("π» Gender", ["Female", "Male", "Other"])
|
| 126 |
+
age = st.slider("π Age", 5, 100, 25)
|
| 127 |
+
skin_concern = st.selectbox("π Select a Common Skin Concern", ["Dark Spots", "Acne", "Tanned Skin", "Oily Skin", "Dryness", "Other"])
|
| 128 |
+
description = st.text_area("π§Ύ Or Describe Your Skin Concern")
|
| 129 |
+
image = st.file_uploader("π· Upload Image (optional)")
|
| 130 |
+
duration = st.selectbox("β³ How long?", ["π Less than a week", "π 1β4 weeks", "π
Over a month"])
|
| 131 |
+
sensitivity = st.selectbox("π§ͺ Sensitive Skin?", ["Yes", "No", "Not Sure"])
|
| 132 |
+
routine = st.selectbox("π§΄ Skincare Routine?", ["Yes", "No"])
|
| 133 |
+
submit = st.form_submit_button("β¨ Get My Personalized Advice")
|
| 134 |
+
|
| 135 |
+
if submit:
|
| 136 |
+
output = skincare_advice(name, gender, age, skin_concern, description, image, duration, sensitivity, routine)
|
| 137 |
+
st.markdown(output, unsafe_allow_html=True)
|