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('
๐Ÿ“ How Would You Like to Start?
', 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('
๐Ÿ” Help Us Understand You Better
', 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('
๐Ÿ“‹ Your Personalized Skin Plan
', 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 """)