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  
""")