JaveriaZia commited on
Commit
f855ccd
·
verified ·
1 Parent(s): ebfbcbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -76,6 +76,11 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
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 = ""
@@ -89,6 +94,10 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
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:
@@ -99,12 +108,16 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
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 = ""
 
76
  except Exception as e:
77
  return f"<span style='color:red;'>❌ Error: {str(e)}</span>"
78
 
79
+ # Clean the raw response first - remove any HTML tags that might be in the AI response
80
+ import html
81
+ raw = html.unescape(raw) # Decode HTML entities
82
+ raw = re.sub(r'<[^>]+>', '', raw) # Remove any HTML tags
83
+
84
  # Format response into HTML
85
  lines = raw.strip().split("\n")
86
  html_output = ""
 
94
  if not stripped:
95
  continue
96
 
97
+ # Skip lines that look like HTML code or contain style attributes
98
+ if '<' in stripped and ('style=' in stripped or '/>' in stripped or '</p>' in stripped):
99
+ continue
100
+
101
  # Check if this line is a section header (starts with emoji and contains expected keywords)
102
  is_section_header = False
103
  for emoji in section_colors:
 
108
  if any(keyword.lower() in stripped.lower() for keyword in header_keywords):
109
  is_section_header = True
110
  color = section_colors[emoji]
111
+ # Escape any remaining HTML characters in the header text
112
+ safe_header = html.escape(stripped)
113
+ html_output += f"<h4 style='color:{color}; margin-top:20px; margin-bottom:10px;'>{safe_header}</h4>\n"
114
  break
115
 
116
  # If not a section header, treat as regular content
117
  if not is_section_header:
118
+ # Escape any HTML characters in the content
119
+ safe_content = html.escape(stripped)
120
+ html_output += f"<p style='color:#111; margin:5px 0; line-height:1.5;'>{safe_content}</p>\n"
121
 
122
  # Embed uploaded image
123
  image_html = ""