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("""
๐ฟ SkinSense AI - Your Personal Skin Care Advisor
""", 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('', 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('', 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('', 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'{line}
', unsafe_allow_html=True)
elif line.strip().startswith("๐"):
st.markdown(f'{line}
', unsafe_allow_html=True)
elif line.strip().startswith("๐งด"):
st.markdown(f'{line}
', unsafe_allow_html=True)
elif line.strip().startswith("๐ฟ"):
st.markdown(f'{line}
', unsafe_allow_html=True)
elif line.strip().startswith("๐ก"):
st.markdown(f'{line}
', unsafe_allow_html=True)
elif line.strip().startswith("๐ฌ"):
st.markdown(f'{line}
', 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
""")