Spaces:
Sleeping
Sleeping
| 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 | |
| """) | |