JaveriaZia commited on
Commit
14b368e
Β·
verified Β·
1 Parent(s): 3a24327

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -59
app.py CHANGED
@@ -1,21 +1,37 @@
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
- # βœ… 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
- # βœ… Function to get advice using Groq LLaMA3
18
- def skincare_advice(name, gender, age, skin_concern, description, image, duration, sensitivity, routine):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  if not name.strip():
20
  return "<span style='color:red;'>⚠ Please enter your name.</span>"
21
 
@@ -35,7 +51,8 @@ def skincare_advice(name, gender, age, skin_concern, description, image, duratio
35
  πŸ’‘ Lifestyle Tips
36
  πŸ’¬ Motivational Quote
37
 
38
- Each section should start with a title and emoji (e.g., 🌿 Natural Remedy) followed by 2–4 lines in plain sentences or bullet points. Only headings should be styled. Don't use HTML tags inside the content.
 
39
  """
40
 
41
  try:
@@ -43,67 +60,48 @@ def skincare_advice(name, gender, age, skin_concern, description, image, duratio
43
  model="llama3-8b-8192",
44
  messages=[{"role": "user", "content": prompt}]
45
  )
46
- content = response.choices[0].message.content
47
  except Exception as e:
48
  return f"<span style='color:red;'>❌ Error: {str(e)}</span>"
49
 
50
- # βœ… Color only the section titles, keep content black and clean
51
- section_styles = {
52
- "🌟": "#4CAF50", # Green
53
- "🩺": "#F44336", # Red
54
- "πŸ“Š": "#3F51B5", # Indigo
55
- "🧴": "#FF9800", # Orange
56
- "🌿": "#8BC34A", # Light Green
57
- "πŸ’‘": "#009688", # Teal
58
- "πŸ’¬": "#9C27B0" # Purple
 
 
59
  }
60
 
61
- for emoji, color in section_styles.items():
62
- content = content.replace(
63
- f"{emoji} ",
64
- f"</div><h4 style='color:{color}; margin-top:20px;'>{emoji} "
65
- )
 
 
 
66
 
67
- # Wrap everything after first header tag
68
  final_html = f"""
69
  <div style='font-family:Arial, sans-serif; color:#111; background:#fff; padding:20px;
70
- border-radius:15px; border:2px solid #000; box-shadow:0px 3px 10px rgba(0,0,0,0.3);'>
71
  <div style='display:flex; align-items:center; justify-content:space-between;'>
72
  <h2 style='color:#000; margin:0;'>πŸ‘€ <b>{name}</b> | {gender}, {age} yrs</h2>
73
  <img src="{sticker}" style="width:70px; border-radius:10px;">
74
  </div>
75
- <div style='margin-top:15px; font-size:16px; line-height:1.7;'>
76
- {content}</div>
 
77
  </div>
78
  """
79
-
80
  return final_html
81
 
82
-
83
- # βœ… Streamlit UI
84
- st.set_page_config(page_title="SkinSense AI", layout="centered")
85
-
86
- st.markdown("""
87
- <h1 style='text-align:center; font-family:Arial; font-size:30px;
88
- background: linear-gradient(to right, black, #4CAF50);
89
- -webkit-background-clip: text; color: transparent;'>
90
- 🌿 <b>Welcome to SkinSense AI – Your Smart Skincare Buddy</b>
91
- </h1>
92
- """, unsafe_allow_html=True)
93
-
94
- with st.form("skincare_form"):
95
- name = st.text_input("πŸ“ Name")
96
- gender = st.selectbox("🚻 Gender", ["Female", "Male", "Other"])
97
- age = st.slider("πŸŽ‚ Age", 5, 100, 25)
98
- skin_concern = st.selectbox("🌟 Select a Common Skin Concern", ["Dark Spots", "Acne", "Tanned Skin", "Oily Skin", "Dryness", "Other"])
99
- description = st.text_area("🧾 Or Describe Your Skin Concern")
100
- image = st.file_uploader("πŸ“· Upload Image (optional)")
101
- duration = st.selectbox("⏳ How long?", ["πŸ†• Less than a week", "πŸ“† 1–4 weeks", "πŸ“… Over a month"])
102
- sensitivity = st.selectbox("πŸ§ͺ Sensitive Skin?", ["Yes", "No", "Not Sure"])
103
- routine = st.selectbox("🧴 Skincare Routine?", ["Yes", "No"])
104
- submit = st.form_submit_button("✨ Get My Personalized Advice")
105
-
106
  if submit:
107
- with st.spinner("🧠 Analyzing and generating your personalized advice..."):
108
- output = skincare_advice(name, gender, age, skin_concern, description, image, duration, sensitivity, routine)
109
- st.markdown(output, unsafe_allow_html=True)
 
1
  import streamlit as st
2
+ import random
3
  from groq import Groq
4
+ import os
5
 
6
+ # Set your GROQ API Key
7
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY", "your_groq_api_key_here") # Replace or set via environment
8
+ client = Groq(api_key=GROQ_API_KEY)
9
 
 
10
  stickers = [
11
+ "https://i.imgur.com/6KZyFxh.png",
12
+ "https://i.imgur.com/f1Qdqpv.png",
13
+ "https://i.imgur.com/UuUJqfL.png",
14
+ "https://i.imgur.com/bGMH89Y.png",
15
+ "https://i.imgur.com/y0ubkNe.png"
16
  ]
17
 
18
+ # App Title
19
+ st.set_page_config(page_title="SkinSense AI", layout="centered")
20
+ st.markdown("<h1 style='text-align:center; color:#5E35B1;'>🌸 SkinSense AI – Skincare Buddy</h1>", unsafe_allow_html=True)
21
+
22
+ # User Inputs
23
+ name = st.text_input("Your Name")
24
+ gender = st.radio("Gender", ["Female", "Male", "Other"])
25
+ age = st.slider("Age", 12, 60, 25)
26
+ skin_concern = st.selectbox("Main Skin Concern", ["Acne", "Dryness", "Oiliness", "Pores", "Dullness", "Pigmentation", "Other"])
27
+ description = st.text_area("Describe Your Skin Problem", placeholder="e.g. Small white pimples under skin for 2 weeks...")
28
+ duration = st.selectbox("How long has this been a concern?", ["Less than 1 week", "1-2 weeks", "More than 2 weeks"])
29
+ sensitivity = st.radio("Is your skin sensitive?", ["Yes", "No", "Not Sure"])
30
+ routine = st.text_input("Do you follow a routine?", placeholder="e.g. Facewash, moisturizer, sunscreen")
31
+
32
+ submit = st.button("✨ Generate Skincare Advice")
33
+
34
+ def skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine):
35
  if not name.strip():
36
  return "<span style='color:red;'>⚠ Please enter your name.</span>"
37
 
 
51
  πŸ’‘ Lifestyle Tips
52
  πŸ’¬ Motivational Quote
53
 
54
+ Each section should start with a title (e.g., 🌿 Natural Remedy) on one line, then 2–4 lines of helpful content below it in plain text or bullet points.
55
+ Do not use bold, underline, or any extra styling.
56
  """
57
 
58
  try:
 
60
  model="llama3-8b-8192",
61
  messages=[{"role": "user", "content": prompt}]
62
  )
63
+ raw = response.choices[0].message.content
64
  except Exception as e:
65
  return f"<span style='color:red;'>❌ Error: {str(e)}</span>"
66
 
67
+ # Formatting logic
68
+ lines = raw.strip().split("\n")
69
+ html_output = ""
70
+ section_colors = {
71
+ "🌟": "#E53935", # red
72
+ "🩺": "#D81B60", # pink
73
+ "πŸ“Š": "#5E35B1", # purple
74
+ "🧴": "#F57C00", # orange
75
+ "🌿": "#43A047", # green
76
+ "πŸ’‘": "#039BE5", # blue
77
+ "πŸ’¬": "#6D4C41", # brown
78
  }
79
 
80
+ for line in lines:
81
+ stripped = line.strip()
82
+ if any(stripped.startswith(e) for e in section_colors):
83
+ emoji = stripped[:2]
84
+ color = section_colors.get(emoji, "#000")
85
+ html_output += f"<h4 style='color:{color}; margin-top:20px;'>{stripped}</h4>\n"
86
+ else:
87
+ html_output += f"<p style='color:#111; margin:5px 0;'>{stripped}</p>\n"
88
 
 
89
  final_html = f"""
90
  <div style='font-family:Arial, sans-serif; color:#111; background:#fff; padding:20px;
91
+ border-radius:12px; border:1px solid #ccc; box-shadow:0 2px 6px rgba(0,0,0,0.1);'>
92
  <div style='display:flex; align-items:center; justify-content:space-between;'>
93
  <h2 style='color:#000; margin:0;'>πŸ‘€ <b>{name}</b> | {gender}, {age} yrs</h2>
94
  <img src="{sticker}" style="width:70px; border-radius:10px;">
95
  </div>
96
+ <div style='margin-top:15px; font-size:16px; line-height:1.6;'>
97
+ {html_output}
98
+ </div>
99
  </div>
100
  """
 
101
  return final_html
102
 
103
+ # Show Response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  if submit:
105
+ with st.spinner("Generating advice..."):
106
+ result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine)
107
+ st.markdown(result, unsafe_allow_html=True)