JaveriaZia commited on
Commit
d2d5f1a
Β·
verified Β·
1 Parent(s): d7d897a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -134
app.py CHANGED
@@ -1,135 +1,57 @@
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()