SsebaA commited on
Commit
3f7070d
·
verified ·
1 Parent(s): fdbbe9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -7,8 +7,7 @@ import gradio as gr
7
  from config import Config, VIPS_CATEGORIES
8
  from gdpr_filter import apply_gdpr_filter
9
  from models import WhisperASR, MistralClient
10
- from vips_classifier import classify_all
11
-
12
 
13
 
14
  logger = logging.getLogger(__name__)
@@ -16,14 +15,14 @@ logger = logging.getLogger(__name__)
16
  asr_model = WhisperASR()
17
  mistral_client = None
18
 
19
- def format_vips_output(text) -> str:
20
- if isinstance(text, dict):
21
- text = str(text)
22
 
23
- if not text or not str(text).strip():
24
  return "No output generated"
25
 
26
- return str(text).strip()
27
 
28
 
29
  def _get_clients():
@@ -55,14 +54,12 @@ def _run_common(swedish_text):
55
  logger.info("Running GDPR filter...")
56
  anonymized_sv = apply_gdpr_filter(swedish_text)
57
 
58
- # Get clients
59
  try:
60
  mc = _get_clients()
61
  except Exception as e:
62
  logger.exception("Client init failed")
63
  return (swedish_text, anonymized_sv, f"[FEL]: {e}", "", "", "")
64
 
65
- # Send to Scaleway LLM
66
  logger.info("Running Scaleway LLM...")
67
  try:
68
  all_results = classify_all(anonymized_sv, mc)
@@ -150,6 +147,7 @@ with gr.Blocks(title="VoiceNote AI") as demo:
150
  lines=5, interactive=False)
151
 
152
  gr.Markdown("##### VIPS - TRE PROMPTSTRATEGIER", elem_classes="section-label")
 
153
  with gr.Row():
154
  with gr.Column(elem_classes="vips-col-zero"):
155
  gr.HTML("<h4>Zero-shot</h4>")
@@ -157,9 +155,10 @@ with gr.Blocks(title="VoiceNote AI") as demo:
157
  with gr.Column(elem_classes="vips-col-few"):
158
  gr.HTML("<h4>Few-shot</h4>")
159
  few_out = gr.Textbox(label="", lines=10, interactive=True)
 
160
  with gr.Column(elem_classes="vips-col-cot"):
161
- gr.HTML("<h4>Chain-of-Thought</h4>")
162
- cot_out = gr.Textbox(label="", lines=10, interactive=True)
163
 
164
  with gr.Group(elem_classes="section-card"):
165
  gr.Markdown("##### UTVARDERING", elem_classes="section-label")
@@ -200,7 +199,6 @@ with gr.Blocks(title="VoiceNote AI") as demo:
200
  interactive=False,
201
  )
202
 
203
- # Event handlers
204
  process_btn.click(
205
  fn=run_pipeline,
206
  inputs=[audio_input, text_input],
@@ -209,7 +207,6 @@ with gr.Blocks(title="VoiceNote AI") as demo:
209
 
210
  def on_save(c, h, s, cl, cm, m, p, t, pe, e, f,
211
  transcription, zero, few, cot):
212
- """Combine pipeline results + evaluation into ONE downloadable file."""
213
  if not any([c, h, s, cl]):
214
  return "Fyll i minst ett svar i Del 1.", None
215
 
@@ -247,11 +244,6 @@ with gr.Blocks(title="VoiceNote AI") as demo:
247
  },
248
  }
249
 
250
- try:
251
- save_evaluation(entry)
252
- except Exception as ex:
253
- logger.warning(f"Server save failed: {ex}")
254
-
255
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
256
  filename = f"/tmp/voicenote_utvardering_{timestamp}.json"
257
  with open(filename, "w", encoding="utf-8") as fh:
@@ -268,7 +260,6 @@ with gr.Blocks(title="VoiceNote AI") as demo:
268
  )
269
 
270
  def clear_all():
271
- """Reset all UI fields - no data remains in interface or memory."""
272
  return (
273
  None, "",
274
  "", "", "", "", "",
 
7
  from config import Config, VIPS_CATEGORIES
8
  from gdpr_filter import apply_gdpr_filter
9
  from models import WhisperASR, MistralClient
10
+ from vips_classifier import classify_all, format_vips_for_display
 
11
 
12
 
13
  logger = logging.getLogger(__name__)
 
15
  asr_model = WhisperASR()
16
  mistral_client = None
17
 
18
+ def format_vips_output(vips_dict) -> str:
19
+ if isinstance(vips_dict, dict):
20
+ return format_vips_for_display(vips_dict)
21
 
22
+ if not vips_dict or not str(vips_dict).strip():
23
  return "No output generated"
24
 
25
+ return str(vips_dict).strip()
26
 
27
 
28
  def _get_clients():
 
54
  logger.info("Running GDPR filter...")
55
  anonymized_sv = apply_gdpr_filter(swedish_text)
56
 
 
57
  try:
58
  mc = _get_clients()
59
  except Exception as e:
60
  logger.exception("Client init failed")
61
  return (swedish_text, anonymized_sv, f"[FEL]: {e}", "", "", "")
62
 
 
63
  logger.info("Running Scaleway LLM...")
64
  try:
65
  all_results = classify_all(anonymized_sv, mc)
 
147
  lines=5, interactive=False)
148
 
149
  gr.Markdown("##### VIPS - TRE PROMPTSTRATEGIER", elem_classes="section-label")
150
+
151
  with gr.Row():
152
  with gr.Column(elem_classes="vips-col-zero"):
153
  gr.HTML("<h4>Zero-shot</h4>")
 
155
  with gr.Column(elem_classes="vips-col-few"):
156
  gr.HTML("<h4>Few-shot</h4>")
157
  few_out = gr.Textbox(label="", lines=10, interactive=True)
158
+
159
  with gr.Column(elem_classes="vips-col-cot"):
160
+ gr.HTML("<h4>Chain-of-Thought</h4>")
161
+ cot_out = gr.Textbox(label="", lines=10, interactive=True)
162
 
163
  with gr.Group(elem_classes="section-card"):
164
  gr.Markdown("##### UTVARDERING", elem_classes="section-label")
 
199
  interactive=False,
200
  )
201
 
 
202
  process_btn.click(
203
  fn=run_pipeline,
204
  inputs=[audio_input, text_input],
 
207
 
208
  def on_save(c, h, s, cl, cm, m, p, t, pe, e, f,
209
  transcription, zero, few, cot):
 
210
  if not any([c, h, s, cl]):
211
  return "Fyll i minst ett svar i Del 1.", None
212
 
 
244
  },
245
  }
246
 
 
 
 
 
 
247
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
248
  filename = f"/tmp/voicenote_utvardering_{timestamp}.json"
249
  with open(filename, "w", encoding="utf-8") as fh:
 
260
  )
261
 
262
  def clear_all():
 
263
  return (
264
  None, "",
265
  "", "", "", "", "",