Marcel0123 commited on
Commit
5f45471
·
verified ·
1 Parent(s): 85e6132

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -59,10 +59,11 @@ def visualize(image, det_res, fer_res):
59
 
60
  def summarize_emotions(fer_res):
61
  """
62
- Maakt een HTML-tekst met een grote, vetgedrukte samenvatting (NL) in groen.
 
63
  """
64
  if not fer_res:
65
- return '<div style="color: green;">## <b>Geen gezicht gedetecteerd</b></div>'
66
 
67
  names_en = [FacialExpressionRecog.getDesc(x) for x in fer_res]
68
  names_nl = [to_dutch(n) for n in names_en]
@@ -70,12 +71,8 @@ def summarize_emotions(fer_res):
70
  top, top_n = counts[0]
71
  details = ", ".join([f"{name} ({n})" for name, n in counts])
72
 
73
- return f'''
74
- <div style="color: green;">
75
- <h1><b>{top}</b></h1>
76
- <p><i>Gedetecteerde emoties: {details}</i></p>
77
- </div>
78
- '''
79
 
80
  def detect_expression(input_image):
81
  image = cv.cvtColor(input_image, cv.COLOR_RGB2BGR)
@@ -112,9 +109,10 @@ example_list = [[p] for p in example_paths]
112
  CACHE_EXAMPLES = bool(example_list)
113
  # =============================================================
114
 
115
- # Gradio Interface (NL)
116
  custom_css = """
117
  .example * { font-style: italic; font-size: 18px !important; color: #0ea5e9 !important; }
 
118
  #emotie-uitslag h1, #emotie-uitslag h2, #emotie-uitslag h3 { margin: 0.25rem 0; }
119
  """
120
 
@@ -129,17 +127,19 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
129
  submit_btn = gr.Button("Verstuur", variant="primary")
130
  clear_btn = gr.Button("Wissen")
131
  with gr.Column(scale=1):
 
132
  output_image = gr.Image(type="numpy", label="Resultaat gezichtsuitdrukking")
133
  emotion_md = gr.Markdown(
134
  value="## **Nog geen resultaat**",
135
- elem_id="emotie-uitslag",
136
- unsafe_allow_html=True
137
  )
138
 
 
139
  def _clear_output_on_new_image():
140
  return None, "## **Nog geen resultaat**"
141
  input_image.change(fn=_clear_output_on_new_image, outputs=[output_image, emotion_md])
142
 
 
143
  submit_btn.click(fn=detect_expression, inputs=input_image, outputs=[output_image, emotion_md])
144
  clear_btn.click(fn=lambda: (None, None, "## **Nog geen resultaat**"),
145
  outputs=[input_image, output_image, emotion_md])
 
59
 
60
  def summarize_emotions(fer_res):
61
  """
62
+ Maakt een Markdown-tekst met een grote, vetgedrukte samenvatting (NL).
63
+ Bij meerdere gezichten wordt de meest voorkomende emotie uitgelicht.
64
  """
65
  if not fer_res:
66
+ return "## **Geen gezicht gedetecteerd**"
67
 
68
  names_en = [FacialExpressionRecog.getDesc(x) for x in fer_res]
69
  names_nl = [to_dutch(n) for n in names_en]
 
71
  top, top_n = counts[0]
72
  details = ", ".join([f"{name} ({n})" for name, n in counts])
73
 
74
+ # Grote headline + toelichting (kleur regelen we via CSS)
75
+ return f"# **{top}**\n\n_Gedetecteerde emoties: {details}_"
 
 
 
 
76
 
77
  def detect_expression(input_image):
78
  image = cv.cvtColor(input_image, cv.COLOR_RGB2BGR)
 
109
  CACHE_EXAMPLES = bool(example_list)
110
  # =============================================================
111
 
112
+ # Gradio Interface (NL) + groene kleur voor de emotietekst
113
  custom_css = """
114
  .example * { font-style: italic; font-size: 18px !important; color: #0ea5e9 !important; }
115
+ #emotie-uitslag { color: #16a34a; } /* GROEN */
116
  #emotie-uitslag h1, #emotie-uitslag h2, #emotie-uitslag h3 { margin: 0.25rem 0; }
117
  """
118
 
 
127
  submit_btn = gr.Button("Verstuur", variant="primary")
128
  clear_btn = gr.Button("Wissen")
129
  with gr.Column(scale=1):
130
+ # Eerst de afbeelding, daaronder de (groene) emotie-uitslag
131
  output_image = gr.Image(type="numpy", label="Resultaat gezichtsuitdrukking")
132
  emotion_md = gr.Markdown(
133
  value="## **Nog geen resultaat**",
134
+ elem_id="emotie-uitslag"
 
135
  )
136
 
137
+ # Output(s) leegmaken bij nieuwe upload
138
  def _clear_output_on_new_image():
139
  return None, "## **Nog geen resultaat**"
140
  input_image.change(fn=_clear_output_on_new_image, outputs=[output_image, emotion_md])
141
 
142
+ # Knop-actie(s)
143
  submit_btn.click(fn=detect_expression, inputs=input_image, outputs=[output_image, emotion_md])
144
  clear_btn.click(fn=lambda: (None, None, "## **Nog geen resultaat**"),
145
  outputs=[input_image, output_image, emotion_md])