Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,135 +1,57 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 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 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def skincare_response(name, concern):
|
| 4 |
+
# Example response based on concern
|
| 5 |
+
if "dark spots" in concern.lower():
|
| 6 |
+
return f"""
|
| 7 |
+
<div style='font-family:Arial, sans-serif; line-height:1.6; color:#333'>
|
| 8 |
+
<h2 style='color:#4CAF50;'>π Hey {name}! πΈ</h2>
|
| 9 |
+
|
| 10 |
+
<h3 style='color:#FF5722;'>π©Ί Skin Issue Summary:</h3>
|
| 11 |
+
<p>You're experiencing <b>dark spots</b>, a common concern, and we're here to help!</p>
|
| 12 |
+
|
| 13 |
+
<h3 style='color:#3F51B5;'>π Global Insight:</h3>
|
| 14 |
+
<p><b>78%</b> of women in their 20s like you suffer from dark spots due to hormonal fluctuations, sun exposure, or skin care mistakes.</p>
|
| 15 |
+
|
| 16 |
+
<h3 style='color:#009688;'>π§΄ Daily Care Routine:</h3>
|
| 17 |
+
<ul style='margin-left:20px;'>
|
| 18 |
+
<li>Cleanse your face with a gentle, sulfate-free cleanser containing ingredients like <b>aloe vera</b> or <b>green tea</b>.</li>
|
| 19 |
+
<li>Apply a toner that balances your skin's pH level and helps reduce dark spots.</li>
|
| 20 |
+
<li>Moisturize with a lightweight, oil-free gel or serum that absorbs quickly into your skin.</li>
|
| 21 |
+
</ul>
|
| 22 |
+
|
| 23 |
+
<h3 style='color:#795548;'>πΏ One Natural Remedy:</h3>
|
| 24 |
+
<p>Try applying a paste made from <b>turmeric powder and yogurt</b> to your dark spots for 10β15 minutes, then rinse with lukewarm water. Turmeric's anti-inflammatory properties help reduce darkness and hyperpigmentation.</p>
|
| 25 |
+
|
| 26 |
+
<h3 style='color:#FF9800;'>π‘ 3 Lifestyle Tips:</h3>
|
| 27 |
+
<ul style='margin-left:20px;'>
|
| 28 |
+
<li>Use a <b>broad-spectrum sunscreen</b> (SPF 30+) and reapply every 2 hours.</li>
|
| 29 |
+
<li>Wear a <b>hat</b> or apply a <b>lip balm with SPF</b> to protect your face and lips.</li>
|
| 30 |
+
<li>Thoroughly remove makeup before bed using a <b>gentle makeup remover</b>.</li>
|
| 31 |
+
</ul>
|
| 32 |
+
|
| 33 |
+
<h3 style='color:#9C27B0;'>π¬ Inspiration:</h3>
|
| 34 |
+
<blockquote style='border-left:4px solid #ccc; padding-left:10px; color:#555; font-style:italic;'>
|
| 35 |
+
βBelieve you can and you're halfway there.β β Theodore Roosevelt
|
| 36 |
+
</blockquote>
|
| 37 |
+
|
| 38 |
+
<p style='color:#E91E63;'><b>Remember, {name}, you're taking the first step towards a brighter, healthier complexion! π</b></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
</div>
|
| 40 |
+
"""
|
| 41 |
+
else:
|
| 42 |
+
return f"<p>Hello {name}, we will add support for your concern soon!</p>"
|
| 43 |
+
|
| 44 |
+
# Gradio interface
|
| 45 |
+
iface = gr.Interface(
|
| 46 |
+
fn=skincare_response,
|
| 47 |
+
inputs=[
|
| 48 |
+
gr.Textbox(label="Your Name"),
|
| 49 |
+
gr.Textbox(label="Describe your skin concern (e.g., dark spots, acne, dryness)")
|
| 50 |
+
],
|
| 51 |
+
outputs=gr.HTML(label="SkinSense AI Response"),
|
| 52 |
+
title="SkinSense AI - Personalized Skincare Guide",
|
| 53 |
+
description="πΏ Enter your name and skin concern to receive a personalized skincare routine and lifestyle tips."
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
iface.launch()
|