JaveriaZia's picture
Create app.py
57bc4d8 verified
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
""")