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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -123
app.py CHANGED
@@ -1,137 +1,59 @@
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)
 
 
 
 
 
 
 
1
  import streamlit as st
 
 
2
 
3
+ def generate_response(name, concern):
4
+ return f"""
5
+ <h4 style='color:red;'>🌟 Greeting</h4>
6
+ <div style='color:black;'>Hey {name}! πŸ‘‹</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ <h4 style='color:red;'>🩺 Skin Issue Summary</h4>
9
+ <div style='color:black;'>
10
+ Skin Issue Summary: {concern} have appeared on your skin, affecting your confidence. It's essential to address this concern to even out your skin tone.
11
+ </div>
12
 
13
+ <h4 style='color:red;'>πŸ“Š Global Insight</h4>
14
+ <div style='color:black;'>
15
+ Global Insight: Did you know that 74% of women experience skin issues during their 20s? It's common to have skin concerns at this age, and with proper care, you can overcome them.
16
+ </div>
 
 
 
 
 
17
 
18
+ <h4 style='color:red;'>🧴 Daily Care Routine</h4>
19
+ <div style='color:black;'>
20
+ β€’ Use a mild cleanser suitable for sensitive skin to avoid stripping your skin of its natural oils.<br>
21
+ β€’ Apply a hyaluronic acid serum to lock in moisture and soothe your skin.<br>
22
+ β€’ Finish your routine with a lightweight, non-comedogenic moisturizer to provide long-lasting hydration.
23
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ <h4 style='color:red;'>🌿 Natural Remedy</h4>
26
+ <div style='color:black;'>
27
+ One Natural Remedy: Try using aloe vera gel on your dark spots. Aloe vera has anti-inflammatory properties that can help reduce the appearance of dark spots and hyperpigmentation.
28
+ </div>
29
 
30
+ <h4 style='color:red;'>πŸ’‘ Lifestyle Tips</h4>
31
+ <div style='color:black;'>
32
+ 3 Lifestyle Tips:<br>
33
+ β€’ Get at least 7–8 hours of sleep to help your skin regenerate and repair itself.<br>
34
+ β€’ Drink plenty of water throughout the day to keep your skin hydrated from the inside out.<br>
35
+ β€’ Avoid picking or squeezing your skin, as this can cause further darkening of the spots and lead to scarring.
36
+ </div>
 
 
 
 
 
 
 
 
37
 
38
+ <div style='color:black; font-weight:bold; margin-top:10px;'>
39
+ _Your skin is a canvas, paint it with kindness and care._
 
 
 
 
 
 
 
 
40
  </div>
41
+
42
+ <h4 style='color:red;'>πŸ’¬ Quote</h4>
43
+ <div style='color:black;'>β€œDo something today that your future self will thank you for.”</div>
44
  """
45
 
46
+ # Streamlit UI
47
  st.set_page_config(page_title="SkinSense AI", layout="centered")
 
 
 
 
 
 
 
48
 
49
+ st.title("🧴 SkinSense AI - Personalized Skincare Assistant")
 
 
 
 
 
 
 
 
 
 
50
 
51
+ with st.form("skincare_form"):
52
+ name = st.text_input("Your Name", placeholder="e.g., Javeria")
53
+ concern = st.text_area("Describe Your Skin Concern", placeholder="e.g., I have dark spots on my cheeks")
54
+ submit = st.form_submit_button("Get My Skincare Plan")
55
+
56
+ if submit and name and concern:
57
+ st.markdown("---")
58
+ st.subheader("🧾 Your Personalized Skin Guide")
59
+ st.markdown(generate_response(name, concern), unsafe_allow_html=True)