Shirjannn commited on
Commit
af372d5
·
verified ·
1 Parent(s): 72e2969

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -63
app.py CHANGED
@@ -1,81 +1,39 @@
1
  import gradio as gr
2
- import time # For progress bar simulation
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
- ## 🔍 Analysis Results (Image)
25
- - **Most likely:** Mild acne (70% confidence)
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 general_guidance()
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
- def general_guidance():
46
- return """
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("Text Chat"):
59
  chatbot = gr.ChatInterface(
60
  analyze_skin,
61
- examples=["How to treat dark spots?", "Is this mole dangerous?"],
62
- submit_btn="Analyze 🧐"
63
  )
64
 
65
- with gr.Tab("Image Analysis"):
66
- with gr.Row():
67
- img_input = gr.Image(type="filepath", label="Upload Skin Image")
68
- img_output = gr.Image(label="Analysis Highlight", height=300, width=300) # تغییر اینجا
69
- with gr.Row():
70
- progress = gr.ProgressBar(label="Processing...", visible=False)
71
- analyze_btn = gr.Button("Analyze Image", variant="primary")
 
 
72
 
73
- # Image analysis logic
74
  def analyze_image(img):
75
  progress.visible = True
76
- yield {"value": 0, "visible": True}
77
- time.sleep(2) # Simulate processing
78
- yield {"value": 100, "visible": False}
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(