Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,37 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
from groq import Groq
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
# β
Skincare GIFs
|
| 9 |
stickers = [
|
| 10 |
-
"https://
|
| 11 |
-
"https://
|
| 12 |
-
"https://
|
| 13 |
-
"https://
|
| 14 |
-
"https://
|
| 15 |
]
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 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 |
-
|
| 47 |
except Exception as e:
|
| 48 |
return f"<span style='color:red;'>β Error: {str(e)}</span>"
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
"
|
| 58 |
-
"
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
-
for
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 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:
|
| 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.
|
| 76 |
-
{
|
|
|
|
| 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("
|
| 108 |
-
|
| 109 |
-
st.markdown(
|
|
|
|
| 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)
|