lamba66 commited on
Commit
e6cecfc
·
verified ·
1 Parent(s): 67e3ffc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -41
app.py CHANGED
@@ -1,48 +1,81 @@
1
- # charger le modèle bart-large-cnn
2
- summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn")
3
- # charger le modèle mT5_multilingual_XLSum
4
- summarizer_1= pipeline("summarization", model="csebuetnlp/mT5_multilingual_XLSum")
5
- # Définir une fonction summarize_func avec bart_large-cnn
6
- def summarize_func(input, min_length, max_length):
7
- output = summarizer(input.strip(),min_length, max_length)
8
- return output[0]['summary_text']
9
-
10
- # Définir une fonction summarize_func avec mT5-multilingual
11
- def summarize_func_1(input, min_length, max_length):
12
- output = summarizer_1(input.strip(), min_length, max_length)
13
- return output[0]['summary_text']
14
-
15
- # Déployer
16
  import gradio as gr
17
- import os
18
- # Création de blocks
19
- demo = gr.Blocks(theme='NoCrypt/miku')
20
- inputs = [gr.Textbox(label="Text à résumer", lines=6),
21
- gr.Number(label = 'Longueur Minimal'),
22
- gr.Number(label = 'Longueur Maximal')]
23
- summarizer1 = gr.Interface(fn=summarize_func,
24
- inputs=inputs,
25
- outputs=[gr.Textbox(label="Résumé", lines=3)],
26
- title="Text summarization avec bart-large-cnn",
27
- description="Résumer n'importe quel texte avec bart-large-cnn"
28
- )
29
- inputs1 = [gr.Textbox(label="Text à résumer", lines=6),
30
- gr.Number(label = 'Longueur Minimal'),
31
- gr.Number(label = 'Longueur Maximal')]
32
-
33
- summarizer2 = gr.Interface(fn=summarize_func_1,
34
- inputs=inputs1,
35
- outputs=[gr.Textbox(label="Result", lines=3)],
36
- title="Text summarization avec mT5_multilingual_XLSum",
37
- description="Résumer n'importe quel texte mT5_multilingual_XLSum"
38
- )
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  with demo:
41
  gr.TabbedInterface(
42
- [summarizer1,
43
- summarizer2],
44
- ["Summarize avec mT5",
45
- "Summarize avec bart"],
 
 
 
 
46
  )
47
 
48
  demo.launch()
 
1
+ # importer gradio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import gradio as gr
3
+ from transformers import pipeline
4
+ # Importer nemo.collections.asr
5
+ import nemo.collections.asr as nemo_asr
6
+ # Instancier le modèle canary
7
+ asr_canary = nemo_asr.models.ASRModel.from_pretrained("nvidia/canary-1b-flash")
8
+ # Instanstier le modèle whisper
9
+ asr_whisper = pipeline("automatic-speech-recognition", model="openai/whisper-small")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ # Fonction de transcription whisper
12
+ def transcrire1(fpath):
13
+ output = asr_whisper(fpath)
14
+ return output["text"]
15
+
16
+ # Fonction de transcription canary-1b-flash
17
+ def transcrire2(fpath, source_lang, target_lang):
18
+ transcriptions = asr_canary.transcribe([fpath],
19
+ source_lang = source_lang, target_lang = target_lang)
20
+ text = transcriptions[0].text
21
+
22
+ return text
23
+
24
+ # Créer les blocs
25
+ demo = gr.Blocks(theme='JohnSmith9982/small_and_pretty')
26
+ # Créer un interface ASR whisper avec un microphone
27
+ mic_transcrire = gr.Interface(
28
+ fn=transcrire1,
29
+ inputs=gr.Audio(sources="microphone",
30
+ type="filepath"),
31
+ cache_examples=True,
32
+ outputs=gr.Textbox(label="Transcription",
33
+ lines=3),
34
+ title = 'Transcrire par microphone - Whisper')
35
+
36
+ # Créer un interface ASR whisper par audio
37
+ fich_transcrire = gr.Interface(
38
+ fn=transcrire1,
39
+ inputs=gr.Audio(sources="upload",
40
+ type="filepath"),
41
+ outputs=gr.Textbox(label="Transcription",
42
+ lines=3),
43
+ title = 'Transcrire un fichier audio - Whisper'
44
+ )
45
+
46
+ # Créer un interface ASR canary avec un microphone
47
+ mic_transcrire1 = gr.Interface(
48
+ fn=transcrire2,
49
+ inputs=[gr.Audio(sources="microphone",type="filepath"),
50
+ gr.Dropdown(choices = ['fr', 'en'], label ='Source languge'),
51
+ gr.Dropdown(choices = ['fr', 'en'], label = 'Target language')],
52
+ cache_examples=True,
53
+ outputs=gr.Textbox(label="Transcription",
54
+ lines=3),
55
+ title = 'Transcrire par microphone - Canary')
56
+
57
+ # Créer un interface ASR canary par audio
58
+ fich_transcrire1 = gr.Interface(
59
+ fn=transcrire2,
60
+ inputs=[gr.Audio(sources="upload",type="filepath"),
61
+ gr.Dropdown(choices = ['fr', 'en'], label ='Source languge'),
62
+ gr.Dropdown(choices = ['fr', 'en'], label ='Target language')],
63
+ outputs=gr.Textbox(label="Transcription",
64
+ lines=3),
65
+ title= 'Transcrire un fichier audio - Canary'
66
+ )
67
+
68
+ # Faire un tabbed des interfaces sur demo
69
  with demo:
70
  gr.TabbedInterface(
71
+ [mic_transcrire,
72
+ fich_transcrire,
73
+ mic_transcrire1,
74
+ fich_transcrire1],
75
+ ["Transcrire Microphone",
76
+ "Transcrire Audio",
77
+ "Transcrire Microphone",
78
+ "Transcrire Audio"],
79
  )
80
 
81
  demo.launch()