Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import os
|
|
| 4 |
import re
|
| 5 |
from groq import Groq
|
| 6 |
import base64
|
| 7 |
-
import html
|
| 8 |
|
| 9 |
# Set your GROQ API Key
|
| 10 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "your_groq_api_key_here") # Replace with your actual key or set via environment
|
|
@@ -82,9 +81,9 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
|
|
| 82 |
raw = html.unescape(raw) # Decode HTML entities
|
| 83 |
raw = re.sub(r'<[^>]+>', '', raw) # Remove any HTML tags
|
| 84 |
|
| 85 |
-
# Format response
|
| 86 |
lines = raw.strip().split("\n")
|
| 87 |
-
|
| 88 |
section_colors = {
|
| 89 |
"π": "#E53935", "π©Ί": "#D81B60", "π": "#5E35B1",
|
| 90 |
"π§΄": "#F57C00", "πΏ": "#43A047", "π‘": "#039BE5", "π¬": "#6D4C41"
|
|
@@ -109,16 +108,22 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
|
|
| 109 |
if any(keyword.lower() in stripped.lower() for keyword in header_keywords):
|
| 110 |
is_section_header = True
|
| 111 |
color = section_colors[emoji]
|
| 112 |
-
#
|
| 113 |
-
|
| 114 |
-
html_output += f"<h4 style='color:{color}; margin-top:20px; margin-bottom:10px;'>{safe_header}</h4>\n"
|
| 115 |
break
|
| 116 |
|
| 117 |
# If not a section header, treat as regular content
|
| 118 |
if not is_section_header:
|
| 119 |
-
#
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Embed uploaded image
|
| 124 |
image_html = ""
|
|
@@ -147,4 +152,7 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
|
|
| 147 |
if submit:
|
| 148 |
with st.spinner("Generating advice..."):
|
| 149 |
result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine, image)
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import re
|
| 5 |
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") # Replace with your actual key or set via environment
|
|
|
|
| 81 |
raw = html.unescape(raw) # Decode HTML entities
|
| 82 |
raw = re.sub(r'<[^>]+>', '', raw) # Remove any HTML tags
|
| 83 |
|
| 84 |
+
# Format response using markdown and simple text formatting
|
| 85 |
lines = raw.strip().split("\n")
|
| 86 |
+
formatted_content = ""
|
| 87 |
section_colors = {
|
| 88 |
"π": "#E53935", "π©Ί": "#D81B60", "π": "#5E35B1",
|
| 89 |
"π§΄": "#F57C00", "πΏ": "#43A047", "π‘": "#039BE5", "π¬": "#6D4C41"
|
|
|
|
| 108 |
if any(keyword.lower() in stripped.lower() for keyword in header_keywords):
|
| 109 |
is_section_header = True
|
| 110 |
color = section_colors[emoji]
|
| 111 |
+
# Use HTML span for colored headers
|
| 112 |
+
formatted_content += f"<br><span style='color:{color}; font-weight:bold; font-size:18px;'>{stripped}</span><br>\n"
|
|
|
|
| 113 |
break
|
| 114 |
|
| 115 |
# If not a section header, treat as regular content
|
| 116 |
if not is_section_header:
|
| 117 |
+
# Clean content and add as regular text
|
| 118 |
+
clean_content = stripped.replace('<', '<').replace('>', '>')
|
| 119 |
+
formatted_content += f"{clean_content}<br>\n"
|
| 120 |
+
|
| 121 |
+
# Build the final response with proper HTML structure
|
| 122 |
+
html_output = f"""
|
| 123 |
+
<div style='margin: 10px 0;'>
|
| 124 |
+
{formatted_content}
|
| 125 |
+
</div>
|
| 126 |
+
"""
|
| 127 |
|
| 128 |
# Embed uploaded image
|
| 129 |
image_html = ""
|
|
|
|
| 152 |
if submit:
|
| 153 |
with st.spinner("Generating advice..."):
|
| 154 |
result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine, image)
|
| 155 |
+
if result.startswith("<span style='color:red;'>"):
|
| 156 |
+
st.markdown(result, unsafe_allow_html=True)
|
| 157 |
+
else:
|
| 158 |
+
st.markdown(result, unsafe_allow_html=True)
|