Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from groq import Groq
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# --- Initialize GROQ client ---
|
| 7 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 8 |
+
|
| 9 |
+
# --- Streamlit Page Setup ---
|
| 10 |
+
st.set_page_config(page_title="πΏ SkinSense AI", layout="centered")
|
| 11 |
+
st.markdown("""
|
| 12 |
+
<style>
|
| 13 |
+
.big-title {
|
| 14 |
+
font-size: 36px;
|
| 15 |
+
color: #4CAF50;
|
| 16 |
+
font-weight: bold;
|
| 17 |
+
text-align: center;
|
| 18 |
+
}
|
| 19 |
+
.section-header {
|
| 20 |
+
background-color: #f2f2f2;
|
| 21 |
+
padding: 10px;
|
| 22 |
+
border-radius: 10px;
|
| 23 |
+
margin-top: 25px;
|
| 24 |
+
font-size: 22px;
|
| 25 |
+
color: #0077b6;
|
| 26 |
+
}
|
| 27 |
+
.highlight {
|
| 28 |
+
background-color: #e7f3fe;
|
| 29 |
+
padding: 10px;
|
| 30 |
+
border-left: 5px solid #2196F3;
|
| 31 |
+
border-radius: 5px;
|
| 32 |
+
}
|
| 33 |
+
.remedy-box {
|
| 34 |
+
background-color: #fff3cd;
|
| 35 |
+
padding: 10px;
|
| 36 |
+
border-left: 5px solid #ffc107;
|
| 37 |
+
border-radius: 5px;
|
| 38 |
+
}
|
| 39 |
+
.motivation-box {
|
| 40 |
+
background-color: #d4edda;
|
| 41 |
+
padding: 10px;
|
| 42 |
+
border-left: 5px solid #28a745;
|
| 43 |
+
border-radius: 5px;
|
| 44 |
+
font-style: italic;
|
| 45 |
+
font-weight: bold;
|
| 46 |
+
}
|
| 47 |
+
</style>
|
| 48 |
+
<div class="big-title">πΏ SkinSense AI - Your Personal Skin Care Advisor</div>
|
| 49 |
+
""", unsafe_allow_html=True)
|
| 50 |
+
|
| 51 |
+
st.markdown("Welcome to **SkinSense AI** β your smart assistant for skincare advice, natural remedies, and routine tips. πββοΈ")
|
| 52 |
+
|
| 53 |
+
# --- Input Method ---
|
| 54 |
+
st.markdown('<div class="section-header">π How Would You Like to Start?</div>', unsafe_allow_html=True)
|
| 55 |
+
input_method = st.radio("", ["π Text Description", "π· Upload an Image"])
|
| 56 |
+
|
| 57 |
+
# --- Input Section ---
|
| 58 |
+
image = None
|
| 59 |
+
user_input = ""
|
| 60 |
+
if input_method == "π· Upload an Image":
|
| 61 |
+
image = st.file_uploader("π€ Upload a clear image of your skin issue:", type=["jpg", "jpeg", "png"])
|
| 62 |
+
user_input = st.text_area("π§Ύ Describe the symptoms you're seeing (e.g., red spots, itching, dryness):")
|
| 63 |
+
|
| 64 |
+
elif input_method == "π Text Description":
|
| 65 |
+
user_input = st.text_area("π§Ύ Describe your skin concern in your own words (e.g., acne, dark spots, rough skin):")
|
| 66 |
+
|
| 67 |
+
# --- Follow-Up Questions ---
|
| 68 |
+
st.markdown('<div class="section-header">π Help Us Understand You Better</div>', unsafe_allow_html=True)
|
| 69 |
+
age = st.slider("π Your Age", 10, 100, 25)
|
| 70 |
+
duration = st.radio("β³ How long has the issue been going on?", ["π Less than a week", "π 1β4 weeks", "π
Over a month"])
|
| 71 |
+
sensitivity = st.radio("π§ͺ Do you have sensitive skin?", ["Yes", "No", "Not Sure"])
|
| 72 |
+
routine = st.radio("π§΄ Do you follow any skincare routine?", ["Yes", "No"])
|
| 73 |
+
|
| 74 |
+
# --- AI Processing ---
|
| 75 |
+
if st.button("β¨ Get My Personalized Advice"):
|
| 76 |
+
if not user_input.strip():
|
| 77 |
+
st.warning("β οΈ Please provide some description or upload an image to continue.")
|
| 78 |
+
else:
|
| 79 |
+
with st.spinner("π§ Thinking..."):
|
| 80 |
+
prompt = f"""
|
| 81 |
+
A user reports a skin issue with the following details:
|
| 82 |
+
Age: {age}
|
| 83 |
+
Duration: {duration}
|
| 84 |
+
Sensitivity: {sensitivity}
|
| 85 |
+
Skincare Routine: {routine}
|
| 86 |
+
User's Description: {user_input}
|
| 87 |
+
Give a structured response:
|
| 88 |
+
1. π Probable Skin Issue
|
| 89 |
+
2. π Global Percentage Affected
|
| 90 |
+
3. π§΄ Simple Daily Routine
|
| 91 |
+
4. πΏ One Natural Homemade Remedy
|
| 92 |
+
5. π‘ 3 Quick Lifestyle Tips
|
| 93 |
+
6. π¬ One-line Motivational Quote
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
response = client.chat.completions.create(
|
| 97 |
+
model="llama3-70b-8192",
|
| 98 |
+
messages=[{"role": "user", "content": prompt}]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
result = response.choices[0].message.content.strip()
|
| 102 |
+
|
| 103 |
+
# --- Display Result ---
|
| 104 |
+
st.markdown('<div class="section-header">π Your Personalized Skin Plan</div>', unsafe_allow_html=True)
|
| 105 |
+
if image:
|
| 106 |
+
st.image(image, caption="πΈ Your Uploaded Image", use_container_width=True)
|
| 107 |
+
|
| 108 |
+
# --- Split the AI response into parts ---
|
| 109 |
+
lines = result.split("\n")
|
| 110 |
+
current_section = ""
|
| 111 |
+
for line in lines:
|
| 112 |
+
if line.strip().startswith("π"):
|
| 113 |
+
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
|
| 114 |
+
elif line.strip().startswith("π"):
|
| 115 |
+
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
|
| 116 |
+
elif line.strip().startswith("π§΄"):
|
| 117 |
+
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
|
| 118 |
+
elif line.strip().startswith("πΏ"):
|
| 119 |
+
st.markdown(f'<div class="remedy-box">{line}</div>', unsafe_allow_html=True)
|
| 120 |
+
elif line.strip().startswith("π‘"):
|
| 121 |
+
st.markdown(f'<div class="highlight">{line}</div>', unsafe_allow_html=True)
|
| 122 |
+
elif line.strip().startswith("π¬"):
|
| 123 |
+
st.markdown(f'<div class="motivation-box">{line}</div>', unsafe_allow_html=True)
|
| 124 |
+
else:
|
| 125 |
+
st.markdown(line)
|
| 126 |
+
|
| 127 |
+
st.success("π You're one step closer to healthier skin!")
|
| 128 |
+
|
| 129 |
+
# --- Sidebar ---
|
| 130 |
+
st.sidebar.title("π What's Coming Next?")
|
| 131 |
+
st.sidebar.info("""
|
| 132 |
+
πΉ AI-powered progress tracking
|
| 133 |
+
πΉ Ingredient safety checker
|
| 134 |
+
πΉ Smart reminders for your routine
|
| 135 |
+
πΉ PDF report export
|
| 136 |
+
""")
|
| 137 |
+
|