JaveriaZia commited on
Commit
57bc4d8
Β·
verified Β·
1 Parent(s): 741a3c6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -0
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
+