Update app.py
Browse files
app.py
CHANGED
|
@@ -1,81 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import time
|
| 3 |
-
|
| 4 |
-
# Custom CSS for styling (linked automatically in Gradio)
|
| 5 |
-
css = """
|
| 6 |
-
.chat-message.user {
|
| 7 |
-
background: #E3F2FD !important;
|
| 8 |
-
border-radius: 15px 15px 0 15px !important;
|
| 9 |
-
}
|
| 10 |
-
.chat-message.bot {
|
| 11 |
-
border: 1px solid #e0e0e0 !important;
|
| 12 |
-
border-radius: 15px 15px 15px 0 !important;
|
| 13 |
-
}
|
| 14 |
-
.warning {color: #FF5252; font-weight: bold;}
|
| 15 |
-
"""
|
| 16 |
|
| 17 |
def analyze_skin(text_input, image_input=None):
|
| 18 |
-
"""Generate AI response based on text/image input"""
|
| 19 |
-
# Simulate AI processing delay
|
| 20 |
time.sleep(1.5)
|
| 21 |
-
|
| 22 |
if image_input:
|
| 23 |
-
return ""
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
- **Recommendations:**
|
| 27 |
-
- Apply benzoyl peroxide 2.5% twice daily
|
| 28 |
-
- Use non-comedogenic moisturizer
|
| 29 |
-
⚠️ <span class='warning'>Consult a doctor if nodules appear.</span>
|
| 30 |
-
"""
|
| 31 |
-
elif "acne" in text_input.lower():
|
| 32 |
-
return acne_response()
|
| 33 |
else:
|
| 34 |
-
return
|
| 35 |
-
|
| 36 |
-
def acne_response():
|
| 37 |
-
return """
|
| 38 |
-
## 🧴 Acne Treatment Plan
|
| 39 |
-
1. **Cleanser:** Salicylic acid wash (AM/PM)
|
| 40 |
-
2. **Treatment:** Benzoyl peroxide 2.5% (PM only)
|
| 41 |
-
3. **Moisturizer:** Oil-free, non-comedogenic
|
| 42 |
-
📅 *Expected improvement:* 4-6 weeks
|
| 43 |
-
"""
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
## 🌟 General Skincare Advice
|
| 48 |
-
- **AM Routine:** Cleanser → Vitamin C → SPF 50+
|
| 49 |
-
- **PM Routine:** Double cleanse → Retinol → Moisturizer
|
| 50 |
-
💡 *Pro tip:* Patch test new products!
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
# --- UI Components ---
|
| 54 |
-
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
| 55 |
-
gr.Markdown("# 🩺 **DermaGenius AI**")
|
| 56 |
-
gr.Markdown("Describe your skin concern or upload an image for analysis")
|
| 57 |
|
| 58 |
-
with gr.Tab("
|
| 59 |
chatbot = gr.ChatInterface(
|
| 60 |
analyze_skin,
|
| 61 |
-
examples=["
|
| 62 |
-
submit_btn="Analyze 🧐"
|
| 63 |
)
|
| 64 |
|
| 65 |
-
with gr.Tab("
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
# Image analysis logic
|
| 74 |
def analyze_image(img):
|
| 75 |
progress.visible = True
|
| 76 |
-
yield {"
|
| 77 |
-
time.sleep(2)
|
| 78 |
-
yield {"
|
| 79 |
return img, analyze_skin("", img)
|
| 80 |
|
| 81 |
analyze_btn.click(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def analyze_skin(text_input, image_input=None):
|
|
|
|
|
|
|
| 5 |
time.sleep(1.5)
|
|
|
|
| 6 |
if image_input:
|
| 7 |
+
return "تصویر شما تحلیل شد. احتمال اگزما یا درماتیت وجود دارد."
|
| 8 |
+
elif "جوش" in text_input:
|
| 9 |
+
return "برای جوش: پاکسازی ملایم + بنزوئیل پراکساید ۲.۵٪"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
else:
|
| 11 |
+
return "لطفاً مشکل پوستی خود را دقیقتر شرح دهید."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
with gr.Blocks(title="مشاور پوست هوشمند") as demo:
|
| 14 |
+
gr.Markdown("# 🩺 ربات پوستشناسی هوشمند")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
with gr.Tab("چت متنی"):
|
| 17 |
chatbot = gr.ChatInterface(
|
| 18 |
analyze_skin,
|
| 19 |
+
examples=["جوش صورت چطور درمان میشه؟", "لک پوستی دارم"]
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
+
with gr.Tab("تجزیه تصویر"):
|
| 23 |
+
with gr.Row(): # خط 65 - اینجا شروع with
|
| 24 |
+
with gr.Column(): # اضافه کردن تورفتگی اینجا
|
| 25 |
+
img_input = gr.Image(label="عکس پوست خود را آپلود کنید")
|
| 26 |
+
analyze_btn = gr.Button("تجزیه و تحلیل")
|
| 27 |
+
with gr.Column():
|
| 28 |
+
img_output = gr.Image(label="نتایج", height=300, width=300)
|
| 29 |
+
|
| 30 |
+
progress = gr.ProgressBar(visible=False)
|
| 31 |
|
|
|
|
| 32 |
def analyze_image(img):
|
| 33 |
progress.visible = True
|
| 34 |
+
yield {"visible": True}
|
| 35 |
+
time.sleep(2)
|
| 36 |
+
yield {"visible": False}
|
| 37 |
return img, analyze_skin("", img)
|
| 38 |
|
| 39 |
analyze_btn.click(
|