JaveriaZia commited on
Commit
036be5e
Β·
verified Β·
1 Parent(s): 1beb09d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -41
app.py CHANGED
@@ -1,58 +1,53 @@
1
  import gradio as gr
2
- from groq import Groq
3
  import os
 
 
 
 
 
4
 
5
- # Initialize Groq client with your API key
6
- client = Groq(api_key=os.getenv("GROQ_API_KEY"))
7
-
8
- # Prompt Template
9
- prompt_template = """
10
- You are SkinSense AI, a gentle and friendly AI-powered skincare assistant. Your task is to analyze the following user-described symptoms and skin concerns. Based on this input, kindly return the following in a friendly tone with emojis and HTML formatting:
11
- 1. Greet the user using their name (if given).
12
- 2. Briefly summarize their skin issue in 1 line.
13
- 3. Give a global skin insight (a short stat or fact).
14
- 4. Suggest a daily care routine with 3 bullet points.
15
- 5. Recommend 1 natural home remedy.
16
- 6. Share 3 lifestyle tips.
17
- 7. End with a motivational quote and a short note of encouragement.
18
-
19
- User Symptoms: {input}
20
  """
21
 
22
- # Main function to generate output
23
- def analyze_skin(input, name):
24
- prompt = prompt_template.format(input=input)
25
-
26
- # Get response from Groq (Mixtral model)
27
- response = client.chat.completions.create(
28
- model="mixtral-8x7b-32768",
29
  messages=[
30
- {"role": "system", "content": "You are a helpful and friendly AI assistant."},
31
  {"role": "user", "content": prompt}
32
- ]
 
33
  )
34
 
35
- raw_output = response.choices[0].message.content
36
-
37
- # Fix <b> tags (auto-close them)
38
- fixed_output = raw_output.replace("<b>", "<b>").replace("</b>", "</b>")
39
-
40
- # Add user name in greeting if provided
41
- if name:
42
- fixed_output = fixed_output.replace("Hi!", f"🌟 Hi {name}! 😊")
43
 
44
- return fixed_output
 
 
 
 
 
 
 
45
 
46
- # Gradio UI setup
47
  iface = gr.Interface(
48
  fn=analyze_skin,
49
- inputs=[
50
- gr.Textbox(label="Describe your skin concern (e.g., dry, acne, oily, sensitive, etc.)"),
51
- gr.Textbox(label="Your name (optional)", placeholder="e.g. Javeria")
52
- ],
53
  outputs=gr.HTML(label="SkinSense AI Response"),
54
- title="SkinSense AI 🧴🌸",
55
- description="A GenAI-powered assistant for personalized skincare advice. Just describe your skin concern and get a full care plan instantly!"
56
  )
57
 
58
  if __name__ == "__main__":
 
1
  import gradio as gr
 
2
  import os
3
+ from groq import Groq
4
+
5
+ # Set your Groq API key (make sure to export it in your environment or manually paste it below for local testing)
6
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
+ client = Groq(api_key=GROQ_API_KEY)
8
 
9
+ def analyze_skin(symptom):
10
+ prompt = f"""
11
+ You are SkinSense AI, a gentle and smart skincare assistant. The user has described their skin concern as: "{symptom}"
12
+
13
+ Please:
14
+ 1. Greet the user with their name "Javeria".
15
+ 2. Give a short, easy-to-understand summary of the skin concern.
16
+ 3. Provide one global skin fact relevant to that concern.
17
+ 4. Recommend a simple 3-step daily skincare routine.
18
+ 5. Suggest one natural home remedy.
19
+ 6. Give 3 practical daily care or lifestyle tips.
20
+ 7. End with a motivational quote about skincare or self-care.
21
+
22
+ Make sure the response is beginner-friendly, encouraging, and feels like a caring advisor. Format the output beautifully using headings, bullet points, and spacing.
 
23
  """
24
 
25
+ chat_completion = client.chat.completions.create(
 
 
 
 
 
 
26
  messages=[
27
+ {"role": "system", "content": "You are a friendly skin care assistant."},
28
  {"role": "user", "content": prompt}
29
+ ],
30
+ model="mixtral-8x7b-32768"
31
  )
32
 
33
+ response = chat_completion.choices[0].message.content
 
 
 
 
 
 
 
34
 
35
+ # Format for cleaner display
36
+ formatted_response = f"""
37
+ <div style="font-family: Arial, sans-serif; color: #333; padding: 10px;">
38
+ <h2 style="color:#4CAF50;">🌟 Hi Javeria! 😊</h2>
39
+ <p>{response.replace('\n', '<br>')}</p>
40
+ </div>
41
+ """
42
+ return formatted_response
43
 
44
+ # Gradio UI
45
  iface = gr.Interface(
46
  fn=analyze_skin,
47
+ inputs=gr.Textbox(lines=3, label="Describe Your Skin Symptoms (e.g., oily, acne, dark spots)", placeholder="Type your skin concerns here..."),
 
 
 
48
  outputs=gr.HTML(label="SkinSense AI Response"),
49
+ title="🌿 SkinSense AI – Your Personal Skin Care Helper",
50
+ description="πŸ‘©β€βš•οΈ Get a personalized skincare routine using GenAI. Just describe your skin symptoms!"
51
  )
52
 
53
  if __name__ == "__main__":