Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from groq import Groq
|
|
| 6 |
import base64
|
| 7 |
|
| 8 |
# Set your GROQ API Key
|
| 9 |
-
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "your_groq_api_key_here")
|
| 10 |
client = Groq(api_key=GROQ_API_KEY)
|
| 11 |
|
| 12 |
# Stickers for response
|
|
@@ -51,21 +51,21 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
|
|
| 51 |
|
| 52 |
# Prompt for the model
|
| 53 |
prompt = f"""
|
| 54 |
-
A user named {name} (Gender: {gender}, Age: {age}) is experiencing a skin issue: "{concern_text}".
|
| 55 |
-
Duration: {duration}, Sensitive skin: {sensitivity}, Routine followed: {routine}.
|
| 56 |
-
|
| 57 |
-
Write a response in sections using emojis and headings only for:
|
| 58 |
-
π Greeting
|
| 59 |
-
π©Ί Skin Issue Summary
|
| 60 |
-
π Global Insight
|
| 61 |
-
π§΄ Daily Skincare Routine
|
| 62 |
-
πΏ Natural Remedy
|
| 63 |
-
π‘ Lifestyle Tips
|
| 64 |
-
π¬ Motivational Quote
|
| 65 |
-
|
| 66 |
-
Each section should start with a title (e.g., πΏ Natural Remedy) on one line, then 2β4 lines of helpful content below it in plain text or bullet points.
|
| 67 |
-
Do not use bold, underline, or any extra styling.
|
| 68 |
-
"""
|
| 69 |
|
| 70 |
try:
|
| 71 |
response = client.chat.completions.create(
|
|
@@ -76,7 +76,7 @@ Do not use bold, underline, or any extra styling. Do NOT return HTML.
|
|
| 76 |
except Exception as e:
|
| 77 |
return f"<span style='color:red;'>β Error: {str(e)}</span>"
|
| 78 |
|
| 79 |
-
# Format response into
|
| 80 |
lines = raw.strip().split("\n")
|
| 81 |
html_output = ""
|
| 82 |
section_colors = {
|
|
@@ -85,15 +85,26 @@ Do not use bold, underline, or any extra styling. Do NOT return HTML.
|
|
| 85 |
}
|
| 86 |
|
| 87 |
for line in lines:
|
| 88 |
-
|
| 89 |
-
if not
|
| 90 |
continue
|
| 91 |
-
|
| 92 |
-
if emoji
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# Embed uploaded image
|
| 99 |
image_html = ""
|
|
@@ -115,10 +126,11 @@ Do not use bold, underline, or any extra styling. Do NOT return HTML.
|
|
| 115 |
{html_output}
|
| 116 |
</div>
|
| 117 |
"""
|
|
|
|
| 118 |
return final_html
|
| 119 |
|
| 120 |
# Handle button press
|
| 121 |
if submit:
|
| 122 |
with st.spinner("Generating advice..."):
|
| 123 |
result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine, image)
|
| 124 |
-
st.markdown(result, unsafe_allow_html=True)
|
|
|
|
| 6 |
import base64
|
| 7 |
|
| 8 |
# Set your GROQ API Key
|
| 9 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "your_groq_api_key_here") # Replace with your actual key or set via environment
|
| 10 |
client = Groq(api_key=GROQ_API_KEY)
|
| 11 |
|
| 12 |
# Stickers for response
|
|
|
|
| 51 |
|
| 52 |
# Prompt for the model
|
| 53 |
prompt = f"""
|
| 54 |
+
A user named {name} (Gender: {gender}, Age: {age}) is experiencing a skin issue: "{concern_text}".
|
| 55 |
+
Duration: {duration}, Sensitive skin: {sensitivity}, Routine followed: {routine}.
|
| 56 |
+
|
| 57 |
+
Write a response in sections using emojis and headings only for:
|
| 58 |
+
π Greeting
|
| 59 |
+
π©Ί Skin Issue Summary
|
| 60 |
+
π Global Insight
|
| 61 |
+
π§΄ Daily Skincare Routine
|
| 62 |
+
πΏ Natural Remedy
|
| 63 |
+
π‘ Lifestyle Tips
|
| 64 |
+
π¬ Motivational Quote
|
| 65 |
+
|
| 66 |
+
Each section should start with a title (e.g., πΏ Natural Remedy) on one line, then 2β4 lines of helpful content below it in plain text or bullet points.
|
| 67 |
+
Do not use bold, underline, or any extra styling.
|
| 68 |
+
"""
|
| 69 |
|
| 70 |
try:
|
| 71 |
response = client.chat.completions.create(
|
|
|
|
| 76 |
except Exception as e:
|
| 77 |
return f"<span style='color:red;'>β Error: {str(e)}</span>"
|
| 78 |
|
| 79 |
+
# Format response into HTML
|
| 80 |
lines = raw.strip().split("\n")
|
| 81 |
html_output = ""
|
| 82 |
section_colors = {
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
for line in lines:
|
| 88 |
+
stripped = line.strip()
|
| 89 |
+
if not stripped:
|
| 90 |
continue
|
| 91 |
+
|
| 92 |
+
# Check if this line is a section header (starts with emoji and contains expected keywords)
|
| 93 |
+
is_section_header = False
|
| 94 |
+
for emoji in section_colors:
|
| 95 |
+
if stripped.startswith(emoji):
|
| 96 |
+
# Additional check to ensure it's actually a header and not content
|
| 97 |
+
header_keywords = ["Greeting", "Skin Issue Summary", "Global Insight", "Daily Skincare Routine",
|
| 98 |
+
"Natural Remedy", "Lifestyle Tips", "Motivational Quote"]
|
| 99 |
+
if any(keyword.lower() in stripped.lower() for keyword in header_keywords):
|
| 100 |
+
is_section_header = True
|
| 101 |
+
color = section_colors[emoji]
|
| 102 |
+
html_output += f"<h4 style='color:{color}; margin-top:20px; margin-bottom:10px;'>{stripped}</h4>\n"
|
| 103 |
+
break
|
| 104 |
+
|
| 105 |
+
# If not a section header, treat as regular content
|
| 106 |
+
if not is_section_header:
|
| 107 |
+
html_output += f"<p style='color:#111; margin:5px 0; line-height:1.5;'>{stripped}</p>\n"
|
| 108 |
|
| 109 |
# Embed uploaded image
|
| 110 |
image_html = ""
|
|
|
|
| 126 |
{html_output}
|
| 127 |
</div>
|
| 128 |
"""
|
| 129 |
+
|
| 130 |
return final_html
|
| 131 |
|
| 132 |
# Handle button press
|
| 133 |
if submit:
|
| 134 |
with st.spinner("Generating advice..."):
|
| 135 |
result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine, image)
|
| 136 |
+
st.markdown(result, unsafe_allow_html=True)
|