JaveriaZia commited on
Commit
bef3485
Β·
verified Β·
1 Parent(s): 239db25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
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 into HTML
86
  lines = raw.strip().split("\n")
87
- html_output = ""
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
- # Escape any remaining HTML characters in the header text
113
- safe_header = html.escape(stripped)
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
- # Escape any HTML characters in the content
120
- safe_content = html.escape(stripped)
121
- html_output += f"<p style='color:#111; margin:5px 0; line-height:1.5;'>{safe_content}</p>\n"
 
 
 
 
 
 
 
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
- st.markdown(result, unsafe_allow_html=True)
 
 
 
 
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('<', '&lt;').replace('>', '&gt;')
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)