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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +131 -50
app.py CHANGED
@@ -1,54 +1,135 @@
1
- import gradio as gr
2
- import os
3
  from groq import Groq
4
 
5
- # Set your Groq API key (make sure to export it in your environment or manually paste it below for local testing)
6
- GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
- client = Groq(api_key=GROQ_API_KEY)
8
-
9
- def analyze_skin(symptom):
10
- prompt = f"""
11
- You are SkinSense AI, a gentle and smart skincare assistant. The user has described their skin concern as: "{symptom}"
12
-
13
- Please:
14
- 1. Greet the user with their name "Javeria".
15
- 2. Give a short, easy-to-understand summary of the skin concern.
16
- 3. Provide one global skin fact relevant to that concern.
17
- 4. Recommend a simple 3-step daily skincare routine.
18
- 5. Suggest one natural home remedy.
19
- 6. Give 3 practical daily care or lifestyle tips.
20
- 7. End with a motivational quote about skincare or self-care.
21
-
22
- Make sure the response is beginner-friendly, encouraging, and feels like a caring advisor. Format the output beautifully using headings, bullet points, and spacing.
23
- """
24
-
25
- chat_completion = client.chat.completions.create(
26
- messages=[
27
- {"role": "system", "content": "You are a friendly skin care assistant."},
28
- {"role": "user", "content": prompt}
29
- ],
30
- model="mixtral-8x7b-32768"
 
 
 
 
 
 
 
31
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- response = chat_completion.choices[0].message.content
34
-
35
- # Format for cleaner display
36
- formatted_response = f"""
37
- <div style="font-family: Arial, sans-serif; color: #333; padding: 10px;">
38
- <h2 style="color:#4CAF50;">🌟 Hi Javeria! 😊</h2>
39
- <p>{response.replace('\n', '<br>')}</p>
40
- </div>
41
- """
42
- return formatted_response
43
-
44
- # Gradio UI
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)