JaveriaZia commited on
Commit
a0569ce
·
verified ·
1 Parent(s): f7e2189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
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") # Replace with your actual key or set via environment
10
  client = Groq(api_key=GROQ_API_KEY)
11
 
12
  # Stickers for response
@@ -51,7 +51,7 @@ 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:
@@ -84,16 +84,32 @@ def skincare_advice(name, gender, age, skin_concern, description, duration, sens
84
  "🧴": "#F57C00", "🌿": "#43A047", "💡": "#039BE5", "💬": "#6D4C41"
85
  }
86
 
 
 
 
87
  for line in lines:
88
- stripped = re.sub(r"</div\s*>", "", line.strip(), flags=re.IGNORECASE)
89
- if not stripped:
90
  continue
91
- if any(stripped.startswith(e) for e in section_colors):
92
- emoji = stripped[:2]
93
- color = section_colors.get(emoji, "#000")
94
- html_output += f"<h4 style='color:{color}; margin-top:20px;'>{stripped}</h4>\n"
 
 
 
 
 
 
 
95
  else:
96
- html_output += f"<p style='color:#111; margin:5px 0;'>{stripped}</p>\n"
 
 
 
 
 
 
97
 
98
  # Embed uploaded image
99
  image_html = ""
@@ -123,7 +139,3 @@ if submit:
123
  with st.spinner("Generating advice..."):
124
  result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine, image)
125
  st.markdown(result, unsafe_allow_html=True)
126
-
127
- # Optional: Demonstration Heading
128
- st.markdown("<h4 style='color:#000; margin-top:20px;'>🌟 Greeting</h4>", unsafe_allow_html=True)
129
- st.write("Hey! This is how the greeting will render in HTML.")
 
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 actual key
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:
 
84
  "🧴": "#F57C00", "🌿": "#43A047", "💡": "#039BE5", "💬": "#6D4C41"
85
  }
86
 
87
+ current_section = None
88
+ section_buffer = []
89
+
90
  for line in lines:
91
+ line = line.strip()
92
+ if not line:
93
  continue
94
+
95
+ emoji = line[:2]
96
+ if emoji in section_colors:
97
+ if current_section:
98
+ html_output += f"<h4 style='color:{section_colors[current_section]}; margin-top:20px;'>{section_title}</h4>\n"
99
+ for l in section_buffer:
100
+ html_output += f"<p style='color:#111; margin:5px 0;'>{l}</p>\n"
101
+ section_buffer = []
102
+
103
+ current_section = emoji
104
+ section_title = line
105
  else:
106
+ section_buffer.append(line)
107
+
108
+ # Flush the final section
109
+ if current_section:
110
+ html_output += f"<h4 style='color:{section_colors[current_section]}; margin-top:20px;'>{section_title}</h4>\n"
111
+ for l in section_buffer:
112
+ html_output += f"<p style='color:#111; margin:5px 0;'>{l}</p>\n"
113
 
114
  # Embed uploaded image
115
  image_html = ""
 
139
  with st.spinner("Generating advice..."):
140
  result = skincare_advice(name, gender, age, skin_concern, description, duration, sensitivity, routine, image)
141
  st.markdown(result, unsafe_allow_html=True)