kanslor821 commited on
Commit
72aa5a1
·
verified ·
1 Parent(s): ff5ad78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -1,4 +1,11 @@
1
  from transformers import pipeline, AutoTokenizer, T5ForConditionalGeneration
 
 
 
 
 
 
 
2
 
3
 
4
  model_name = "IlyaGusev/rut5_base_sum_gazeta"
@@ -23,21 +30,16 @@ def summ_mT5_G(text):
23
  summary = tokenizer.decode(output_ids, skip_special_tokens=True)
24
  return summary
25
 
26
- import torch
27
-
28
 
29
  # punctuation
30
  model_punc, example_texts, languages, punct, apply_te = torch.hub.load(repo_or_dir='snakers4/silero-models', model='silero_te')
31
 
 
32
  def punct(text):
33
  # print(text)
34
  return apply_te(text.lower(), lan='ru')
35
 
36
 
37
- from pyannote.audio import Pipeline
38
- import os
39
-
40
-
41
  pipeline_a = Pipeline.from_pretrained(
42
  "pyannote/speaker-diarization-3.1",
43
  use_auth_token=str(os.getenv("s1")))
@@ -71,15 +73,11 @@ def speackers_list(audio_f : str):
71
 
72
  # speackers = speackers_list(name_of_file)
73
 
74
-
75
-
76
- from faster_whisper import WhisperModel
77
-
78
-
79
  model_size = "large-v3"
80
  # Run on GPU with FP16
81
  model_tts = WhisperModel(model_size) #, lan = "ru") #, device="cpu", compute_type="int8") #, device="cuda", compute_type="float16")
82
 
 
83
  def speach_to_text(file_name):
84
 
85
  segments, info = model_tts.transcribe(file_name, beam_size=5)
@@ -124,7 +122,7 @@ class Segment_text:
124
  def get_speacker(self):
125
  return self.speacker
126
 
127
- from pydub import AudioSegment
128
  def init_segments(speackers, name_of_file):
129
  list_of_segments = []
130
  audio = AudioSegment.from_file(name_of_file)
@@ -147,15 +145,12 @@ def get_text_to_out(list_of_segments : list):
147
  res_sum += seg.get_speacker() + ": " + seg.get_summarization() + "\n"
148
  return res_text, res_sum
149
 
150
- from random import randint
151
-
152
 
153
  def do_smth(file):
154
  audio = AudioSegment.from_wav(file)
155
  name_of_file = "f"+str(randint(1,10**8))
156
  audio.export(name_of_file, format="mp3")
157
 
158
-
159
  speackers = speackers_list(name_of_file)
160
 
161
  list_of_segments = init_segments(speackers, name_of_file)
@@ -164,8 +159,6 @@ def do_smth(file):
164
 
165
  return out_text, out_sum
166
 
167
- import gradio as gr
168
-
169
 
170
  demo = gr.Interface(
171
  do_smth,
 
1
  from transformers import pipeline, AutoTokenizer, T5ForConditionalGeneration
2
+ import torch
3
+ from pyannote.audio import Pipeline
4
+ import os
5
+ from faster_whisper import WhisperModel
6
+ from pydub import AudioSegment
7
+ from random import randint
8
+ import gradio as gr
9
 
10
 
11
  model_name = "IlyaGusev/rut5_base_sum_gazeta"
 
30
  summary = tokenizer.decode(output_ids, skip_special_tokens=True)
31
  return summary
32
 
 
 
33
 
34
  # punctuation
35
  model_punc, example_texts, languages, punct, apply_te = torch.hub.load(repo_or_dir='snakers4/silero-models', model='silero_te')
36
 
37
+
38
  def punct(text):
39
  # print(text)
40
  return apply_te(text.lower(), lan='ru')
41
 
42
 
 
 
 
 
43
  pipeline_a = Pipeline.from_pretrained(
44
  "pyannote/speaker-diarization-3.1",
45
  use_auth_token=str(os.getenv("s1")))
 
73
 
74
  # speackers = speackers_list(name_of_file)
75
 
 
 
 
 
 
76
  model_size = "large-v3"
77
  # Run on GPU with FP16
78
  model_tts = WhisperModel(model_size) #, lan = "ru") #, device="cpu", compute_type="int8") #, device="cuda", compute_type="float16")
79
 
80
+
81
  def speach_to_text(file_name):
82
 
83
  segments, info = model_tts.transcribe(file_name, beam_size=5)
 
122
  def get_speacker(self):
123
  return self.speacker
124
 
125
+
126
  def init_segments(speackers, name_of_file):
127
  list_of_segments = []
128
  audio = AudioSegment.from_file(name_of_file)
 
145
  res_sum += seg.get_speacker() + ": " + seg.get_summarization() + "\n"
146
  return res_text, res_sum
147
 
 
 
148
 
149
  def do_smth(file):
150
  audio = AudioSegment.from_wav(file)
151
  name_of_file = "f"+str(randint(1,10**8))
152
  audio.export(name_of_file, format="mp3")
153
 
 
154
  speackers = speackers_list(name_of_file)
155
 
156
  list_of_segments = init_segments(speackers, name_of_file)
 
159
 
160
  return out_text, out_sum
161
 
 
 
162
 
163
  demo = gr.Interface(
164
  do_smth,