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|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
iface = gr.Interface(
|
| 46 |
-
fn=analyze_skin,
|
| 47 |
-
inputs=gr.Textbox(lines=3, label="Describe Your Skin Symptoms (e.g., oily, acne, dark spots)", placeholder="Type your skin concerns here..."),
|
| 48 |
-
outputs=gr.HTML(label="SkinSense AI Response"),
|
| 49 |
-
title="πΏ SkinSense AI β Your Personal Skin Care Helper",
|
| 50 |
-
description="π©ββοΈ Get a personalized skincare routine using GenAI. Just describe your skin symptoms!"
|
| 51 |
-
)
|
| 52 |
-
|
| 53 |
-
if __name__ == "__main__":
|
| 54 |
-
iface.launch()
|
|
|
|
| 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 |
+
# β
Cute skincare GIFs
|
| 9 |
+
stickers = [
|
| 10 |
+
"https://media.giphy.com/media/3o6Zt481isNVuQI1l6/giphy.gif",
|
| 11 |
+
"https://media.giphy.com/media/l3q2XB76CaWPggiNW/giphy.gif",
|
| 12 |
+
"https://media.giphy.com/media/26tPplGWjN0xLybiU/giphy.gif",
|
| 13 |
+
"https://media.giphy.com/media/3o7TKP9XDb9IzUrJXa/giphy.gif",
|
| 14 |
+
"https://media.giphy.com/media/26Fxy3Iz1ari8oytO/giphy.gif",
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
# β
Streamlit app settings
|
| 18 |
+
st.set_page_config(page_title="SkinSense AI", layout="centered")
|
| 19 |
+
|
| 20 |
+
st.markdown("""
|
| 21 |
+
<h1 style='text-align:center; font-family:Arial; font-size:32px;
|
| 22 |
+
background: linear-gradient(to right, black, #4CAF50);
|
| 23 |
+
-webkit-background-clip: text; color: transparent;'>
|
| 24 |
+
πΏ <b>SkinSense AI β Your Smart Skincare Buddy</b>
|
| 25 |
+
</h1>
|
| 26 |
+
""", unsafe_allow_html=True)
|
| 27 |
+
|
| 28 |
+
with st.form("skincare_form"):
|
| 29 |
+
st.subheader("π€ Personal Information")
|
| 30 |
+
name = st.text_input("π Name")
|
| 31 |
+
gender = st.selectbox("π» Gender", ["Female", "Male", "Other"])
|
| 32 |
+
age = st.slider("π Age", 5, 100, 25)
|
| 33 |
+
|
| 34 |
+
st.subheader("π Skin Details")
|
| 35 |
+
skin_concern = st.selectbox(
|
| 36 |
+
"π Select a Common Skin Concern",
|
| 37 |
+
["Dark Spots", "Acne", "Tanned Skin", "Oily Skin", "Dryness", "Other"]
|
| 38 |
)
|
| 39 |
+
description = st.text_area("π§Ύ Or Describe Your Skin Concern", height=100)
|
| 40 |
+
image = st.file_uploader("π· Upload Image (optional)", type=["png", "jpg", "jpeg"])
|
| 41 |
+
duration = st.selectbox("β³ How long?", ["π Less than a week", "π 1β4 weeks", "π
Over a month"])
|
| 42 |
+
sensitivity = st.selectbox("π§ͺ Sensitive Skin?", ["Yes", "No", "Not Sure"])
|
| 43 |
+
routine = st.selectbox("π§΄ Skincare Routine?", ["Yes", "No"])
|
| 44 |
+
|
| 45 |
+
submitted = st.form_submit_button("β¨ Get My Personalized Advice")
|
| 46 |
+
|
| 47 |
+
if submitted:
|
| 48 |
+
if not name.strip():
|
| 49 |
+
st.warning("β Please enter your name for personalized advice.")
|
| 50 |
+
elif not description.strip() and (skin_concern == "Other" or not skin_concern.strip()):
|
| 51 |
+
st.warning("β Please select or describe your skin concern.")
|
| 52 |
+
else:
|
| 53 |
+
user_issue = description if description.strip() else skin_concern
|
| 54 |
+
random_factor = random.randint(1, 10000)
|
| 55 |
+
|
| 56 |
+
if gender == "Female":
|
| 57 |
+
gender_pref = "Focus on hydration, mild natural ingredients, and avoid harsh scrubs."
|
| 58 |
+
elif gender == "Male":
|
| 59 |
+
gender_pref = "Men often need oil-control and deep cleansing due to thicker skin."
|
| 60 |
+
else:
|
| 61 |
+
gender_pref = "Use a balanced routine suitable for all skin types."
|
| 62 |
+
|
| 63 |
+
prompt = f"""
|
| 64 |
+
User Profile:
|
| 65 |
+
- Name: {name}
|
| 66 |
+
- Gender: {gender}
|
| 67 |
+
- Age: {age}
|
| 68 |
+
- Skin Concern: {skin_concern}
|
| 69 |
+
- Description: {user_issue}
|
| 70 |
+
- Duration: {duration}
|
| 71 |
+
- Sensitive Skin: {sensitivity}
|
| 72 |
+
- Skincare Routine: {routine}
|
| 73 |
+
|
| 74 |
+
Additional Preference based on Gender:
|
| 75 |
+
{gender_pref}
|
| 76 |
+
|
| 77 |
+
Creativity factor: {random_factor}
|
| 78 |
+
|
| 79 |
+
FORMAT STRICTLY:
|
| 80 |
+
π Personalized Greeting (use Name & friendly tone)
|
| 81 |
+
π©Ί Skin Issue Summary (1 concise line)
|
| 82 |
+
π Global Insight (but vary percentage, not same every time)
|
| 83 |
+
π§΄ Daily Care Routine (3 bullet points)
|
| 84 |
+
πΏ One Natural Remedy (unique each time)
|
| 85 |
+
π‘ 3 Lifestyle Tips (not generic, vary)
|
| 86 |
+
π¬ Motivational Quote (1 line, italic)
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
response = client.chat.completions.create(
|
| 91 |
+
model="llama3-8b-8192",
|
| 92 |
+
messages=[{"role": "user", "content": prompt}]
|
| 93 |
+
)
|
| 94 |
+
result = response.choices[0].message.content.strip()
|
| 95 |
+
except:
|
| 96 |
+
result = f"""
|
| 97 |
+
π Hi {name}, great to see you here!
|
| 98 |
+
π©Ί Your skin concern: {skin_concern}
|
| 99 |
+
π Around {random.randint(10,80)}% of people face this issue globally.
|
| 100 |
+
π§΄ Daily Care Routine:
|
| 101 |
+
β’ Cleanse twice daily with a mild face wash
|
| 102 |
+
β’ Hydrate with light moisturizer
|
| 103 |
+
β’ Apply SPF 30 sunscreen before going out
|
| 104 |
+
πΏ Natural Remedy: Honey + turmeric paste for 10 mins once a week
|
| 105 |
+
π‘ Lifestyle Tips:
|
| 106 |
+
β’ Sleep at least 7 hrs daily
|
| 107 |
+
β’ Eat omega-rich foods (fish, nuts)
|
| 108 |
+
β’ Avoid touching your face frequently
|
| 109 |
+
π¬ βYour skin reflects how kindly you treat yourself.β
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
styled_result = (
|
| 113 |
+
result.replace("π", "<h3 style='color:#4CAF50;'>π")
|
| 114 |
+
.replace("π©Ί", "</h3><h3 style='color:#4CAF50;'>π©Ί")
|
| 115 |
+
.replace("π", "</h3><h3 style='color:#4CAF50;'>π")
|
| 116 |
+
.replace("π§΄", "</h3><h3 style='color:#4CAF50;'>π§΄")
|
| 117 |
+
.replace("πΏ", "</h3><h3 style='color:#4CAF50;'>πΏ")
|
| 118 |
+
.replace("π‘", "</h3><h3 style='color:#4CAF50;'>π‘")
|
| 119 |
+
.replace("π¬", "</h3><h3 style='color:#4CAF50;'>π¬") + "</h3>"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
sticker = random.choice(stickers)
|
| 123 |
|
| 124 |
+
st.markdown(f"""
|
| 125 |
+
<div style='font-family:Arial, sans-serif; color:#111; background:#fff; padding:20px;
|
| 126 |
+
border-radius:15px; border:2px solid #000; box-shadow:0px 3px 10px rgba(0,0,0,0.3);'>
|
| 127 |
+
<div style='display:flex; align-items:center; justify-content:space-between;'>
|
| 128 |
+
<h2 style='color:#000; margin:0;'>π€ <b>{name}</b> | {gender}, {age} yrs</h2>
|
| 129 |
+
<img src="{sticker}" style="width:70px; border-radius:10px;">
|
| 130 |
+
</div>
|
| 131 |
+
<div style='margin-top:15px; font-size:16px; line-height:1.7;'>
|
| 132 |
+
{styled_result}
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|