Spaces:
Sleeping
Sleeping
File size: 5,235 Bytes
57bc4d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
import streamlit as st
import os
from groq import Groq
from PIL import Image
# --- Initialize GROQ client ---
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
# --- Streamlit Page Setup ---
st.set_page_config(page_title="πΏ SkinSense AI", layout="centered")
st.markdown("""
<style>
.big-title {
font-size: 36px;
color: #4CAF50;
font-weight: bold;
text-align: center;
}
.section-header {
background-color: #f2f2f2;
padding: 10px;
border-radius: 10px;
margin-top: 25px;
font-size: 22px;
color: #0077b6;
}
.highlight {
background-color: #e7f3fe;
padding: 10px;
border-left: 5px solid #2196F3;
border-radius: 5px;
}
.remedy-box {
background-color: #fff3cd;
padding: 10px;
border-left: 5px solid #ffc107;
border-radius: 5px;
}
.motivation-box {
background-color: #d4edda;
padding: 10px;
border-left: 5px solid #28a745;
border-radius: 5px;
font-style: italic;
font-weight: bold;
}
</style>
<div class="big-title">πΏ SkinSense AI - Your Personal Skin Care Advisor</div>
""", unsafe_allow_html=True)
st.markdown("Welcome to **SkinSense AI** β your smart assistant for skincare advice, natural remedies, and routine tips. πββοΈ")
# --- Input Method ---
st.markdown('<div class="section-header">π How Would You Like to Start?</div>', unsafe_allow_html=True)
input_method = st.radio("", ["π Text Description", "π· Upload an Image"])
# --- Input Section ---
image = None
user_input = ""
if input_method == "π· Upload an Image":
image = st.file_uploader("π€ Upload a clear image of your skin issue:", type=["jpg", "jpeg", "png"])
user_input = st.text_area("π§Ύ Describe the symptoms you're seeing (e.g., red spots, itching, dryness):")
elif input_method == "π Text Description":
user_input = st.text_area("π§Ύ Describe your skin concern in your own words (e.g., acne, dark spots, rough skin):")
# --- Follow-Up Questions ---
st.markdown('<div class="section-header">π Help Us Understand You Better</div>', unsafe_allow_html=True)
age = st.slider("π Your Age", 10, 100, 25)
duration = st.radio("β³ How long has the issue been going on?", ["π Less than a week", "π 1β4 weeks", "π
Over a month"])
sensitivity = st.radio("π§ͺ Do you have sensitive skin?", ["Yes", "No", "Not Sure"])
routine = st.radio("π§΄ Do you follow any skincare routine?", ["Yes", "No"])
# --- AI Processing ---
if st.button("β¨ Get My Personalized Advice"):
if not user_input.strip():
st.warning("β οΈ Please provide some description or upload an image to continue.")
else:
with st.spinner("π§ Thinking..."):
prompt = f"""
A user reports a skin issue with the following details:
Age: {age}
Duration: {duration}
Sensitivity: {sensitivity}
Skincare Routine: {routine}
User's Description: {user_input}
Give a structured response:
1. π Probable Skin Issue
2. π Global Percentage Affected
3. π§΄ Simple Daily Routine
4. πΏ One Natural Homemade Remedy
5. π‘ 3 Quick Lifestyle Tips
6. π¬ One-line Motivational Quote
"""
response = client.chat.completions.create(
model="llama3-70b-8192",
messages=[{"role": "user", "content": prompt}]
)
result = response.choices[0].message.content.strip()
# --- Display Result ---
st.markdown('<div class="section-header">π Your Personalized Skin Plan</div>', unsafe_allow_html=True)
if image:
st.image(image, caption="πΈ Your Uploaded Image", use_container_width=True)
# --- Split the AI response into parts ---
lines = result.split("\n")
current_section = ""
for line in lines:
if line.strip().startswith("π"):
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
elif line.strip().startswith("π"):
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
elif line.strip().startswith("π§΄"):
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
elif line.strip().startswith("πΏ"):
st.markdown(f'<div class="remedy-box">{line}</div>', unsafe_allow_html=True)
elif line.strip().startswith("π‘"):
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
elif line.strip().startswith("π¬"):
st.markdown(f'<div class="motivation-box">{line}</div>', unsafe_allow_html=True)
else:
st.markdown(line)
st.success("π You're one step closer to healthier skin!")
# --- Sidebar ---
st.sidebar.title("π What's Coming Next?")
st.sidebar.info("""
πΉ AI-powered progress tracking
πΉ Ingredient safety checker
πΉ Smart reminders for your routine
πΉ PDF report export
""")
|