JaveriaZia commited on
Commit
6bf65bd
Β·
verified Β·
1 Parent(s): 4da81a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -93
app.py CHANGED
@@ -1,101 +1,137 @@
1
  import streamlit as st
 
 
2
 
3
- # --- Streamlit Page Config ---
4
- st.set_page_config(page_title="SkinSense AI", layout="centered")
5
 
6
- # --- Title ---
7
- st.markdown("""
8
- <h1 style='text-align: center; color: #4CAF50;'>🌿 SkinSense AI - Your Skincare Companion 🌿</h1>
9
- """, unsafe_allow_html=True)
 
 
 
 
10
 
11
- # --- Input Form ---
12
- st.markdown("## πŸ‘‡ Tell us about your skin")
13
- name = st.text_input("Your Name")
14
- concern = st.text_area("Describe your skin concern")
15
-
16
- # --- Response Logic ---
17
- def skincare_response(name, concern):
18
- concern = concern.lower()
19
- response = f"<h2 style='color: red;'>πŸ‘‹ Hey {name}!</h2>"
20
-
21
- if "dark spots" in concern:
22
- response += """
23
- <h3 style='color: red;'>Lifestyle Changes:</h3>
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
- response += """
87
- <h3 style='color: red;'>Thanks for reaching out!</h3>
88
- <ul style='color:black;'>
89
- <li>Please provide more specific symptoms (like acne, dryness, dark spots, etc.)</li>
90
- </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  """
92
 
93
- return response
94
 
95
- # --- Submit Button ---
96
- if st.button("Get Advice"):
97
- if name and concern:
98
- result = skincare_response(name, concern)
99
- st.markdown(result, unsafe_allow_html=True)
100
- else:
101
- st.warning("Please enter your name and skin concern.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)