Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,53 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from groq import Groq
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
User Symptoms: {input}
|
| 20 |
"""
|
| 21 |
|
| 22 |
-
|
| 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
|
| 31 |
{"role": "user", "content": prompt}
|
| 32 |
-
]
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Gradio UI
|
| 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="
|
| 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__":
|