serge-wilson
commited on
Commit
•
1dca987
1
Parent(s):
1229032
Add application file
Browse files- demo.py +15 -0
- pipeline.py +27 -0
- requirements.txt +2 -0
demo.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio.components import Text
|
3 |
+
from pipeline import transcription_classification_pipeline
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
demo = gr.Interface(
|
8 |
+
title="Sentimment Analysis - FRENCH",
|
9 |
+
fn=transcription_classification_pipeline,
|
10 |
+
inputs = gr.Audio(source="microphone", type="filepath"),
|
11 |
+
outputs = [Text(label="Transcription"), Text(label="Prediction")]
|
12 |
+
)
|
13 |
+
|
14 |
+
|
15 |
+
demo.launch()
|
pipeline.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
2 |
+
|
3 |
+
|
4 |
+
model_name = 'serge-wilson/sentiment_analysis_fr'
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
+
|
8 |
+
#Creation des pipelines
|
9 |
+
classifier = pipeline("text-classification", model = model,tokenizer = tokenizer) #pipeline pour la classification
|
10 |
+
transcriber = pipeline("automatic-speech-recognition", model="bhuang/asr-wav2vec2-french") #pipeline pour la transcription
|
11 |
+
|
12 |
+
|
13 |
+
def transcription_classification_pipeline(audio):
|
14 |
+
"""
|
15 |
+
Cette fonction fonction prend en entrée un audio et renvoie la transcription, la classe prédite et le score (en HTML)
|
16 |
+
"""
|
17 |
+
|
18 |
+
#On passe l'argument "audio" au pipeline transcriber, on repurère le text et on le stocke dans la variable transcription
|
19 |
+
transcription = transcriber(audio)["text"]
|
20 |
+
|
21 |
+
#On passe la variable "transcription" au pipeline classifier et on stocke la valeur de retour(resultat) dans la variable "result"
|
22 |
+
result = classifier(transcription, truncation=True)[0]
|
23 |
+
|
24 |
+
#On recupère le label du resultat
|
25 |
+
predicted_label = result.get("label")
|
26 |
+
|
27 |
+
return transcription, predicted_label.capitalize()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
transformers
|