sotirios-slv commited on
Commit
1a27263
1 Parent(s): 75795f2

Added highlighted text

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -15,13 +15,15 @@ description = """
15
  </div>
16
  """
17
 
18
- diction_text = """
 
 
19
  <div>
20
- <p>How now brown cow</p>
21
  </div>
22
  """
23
 
24
- diction = gr.HTML(diction_text)
25
 
26
 
27
  device = "cpu"
@@ -52,15 +54,32 @@ pipe = pipeline(
52
  )
53
 
54
 
 
 
 
 
 
 
 
 
 
 
55
  def transcribe_audio(audio):
56
  result = pipe(audio)
57
  print(f'TRANSCRIPTION {result["text"]}')
58
- try:
59
- for r in result:
60
- print(r)
61
- except:
62
- print("ERROR")
63
- return result
 
 
 
 
 
 
 
64
 
65
 
66
  input_audio = gr.Audio(
@@ -76,7 +95,7 @@ input_audio = gr.Audio(
76
  demo = gr.Interface(
77
  fn=transcribe_audio,
78
  inputs=[diction, input_audio],
79
- outputs="text",
80
  title="Test your diction",
81
  description=description,
82
  theme="abidlabs/Lime",
 
15
  </div>
16
  """
17
 
18
+ diction_text = "How now brown cow"
19
+
20
+ test_text = f"""
21
  <div>
22
+ <p>{diction_text}</p>
23
  </div>
24
  """
25
 
26
+ diction = gr.HTML(test_text)
27
 
28
 
29
  device = "cpu"
 
54
  )
55
 
56
 
57
+ def diff_texts(audio_input: str):
58
+ test_text = diction_text
59
+ d = Differ()
60
+
61
+ return [
62
+ (token[2:], token[0] if token[0] != "" else None)
63
+ for token in d.compare(test_text, audio_input)
64
+ ]
65
+
66
+
67
  def transcribe_audio(audio):
68
  result = pipe(audio)
69
  print(f'TRANSCRIPTION {result["text"]}')
70
+ diff_text = diff_texts(result["text"])
71
+
72
+ print("diff", diff_text)
73
+
74
+ return diff_text
75
+
76
+
77
+ highlighted_results = gr.HighlightedText(
78
+ label="Diff",
79
+ combine_adjacent=True,
80
+ show_legend=True,
81
+ color_map={"+": "red", "-": "green"},
82
+ )
83
 
84
 
85
  input_audio = gr.Audio(
 
95
  demo = gr.Interface(
96
  fn=transcribe_audio,
97
  inputs=[diction, input_audio],
98
+ outputs=highlighted_results,
99
  title="Test your diction",
100
  description=description,
101
  theme="abidlabs/Lime",