abdoulayee commited on
Commit
3e39a0b
·
verified ·
1 Parent(s): 6ff183c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -23
app.py CHANGED
@@ -3,7 +3,6 @@ import tensorflow as tf
3
  import numpy as np
4
  import joblib
5
  from tensorflow.keras.preprocessing.sequence import pad_sequences
6
- from transformers import pipeline
7
  # Fonction de prédiction pour le lstm
8
  def analyser_sentiment_lstm(tweet):
9
  sequence = tokenizer.texts_to_sequences([tweet])
@@ -13,13 +12,6 @@ def analyser_sentiment_lstm(tweet):
13
  sentiment = "Positif" if prediction[0] >= 0.5 else "Négatif"
14
  return {sentiment: float(prediction[0]) if sentiment == "Positif" else 1 - float(prediction[0])}
15
 
16
- def analyser_sentiment_camembert(tweet):
17
- # charger le modèle
18
- sentiment_pipeline = pipeline("sentiment-analysis", model="cmarkea/distilcamembert-base-sentiment")
19
-
20
- # appliquer le modèle
21
- result = sentiment_pipeline(tweet)[0]['label']
22
-
23
 
24
  # Charger le modèle LSTM
25
  model = tf.keras.models.load_model("lstm_model.h5")
@@ -27,30 +19,17 @@ model = tf.keras.models.load_model("lstm_model.h5")
27
  # Charger le tokenizer utilisé pendant l'entraînement
28
  tokenizer = joblib.load('tokenizer.joblib')
29
 
30
- # définir les blocks
31
- demo = gr.Blocks(theme='shivi/calm_seafoam')
32
-
33
  # Interface Gradio
34
  interface1 = gr.Interface(
35
  fn=analyser_sentiment_lstm,
36
  inputs=gr.Textbox(lines=3, placeholder="Entrez un tweet en français ici..."),
37
  outputs=gr.Label(num_top_classes=2),
38
  title="Analyse de Sentiment de Tweets",
39
- description="Entrez un tweet en français pour obtenir son sentiment (positif, négatif)."
40
- )
41
-
42
- interface2 = gr.Interface(
43
- fn = analyser_sentiment_camembert,
44
- inputs=gr.Textbox(lines=3, placeholder="Entrez un tweet en français ici..."),
45
- outputs=gr.Textbox(label='Output'),
46
- title="Analyse de Sentiment de Tweets",
47
- description="Entrez un tweet en français pour obtenir son sentiment."
48
  )
49
 
50
 
51
- # faire un tabbing des interfaces
52
- with demo:
53
- gr.TabbedInterface([interface1, interface2], ['LSTM_SAM', 'CAMEMBERT_SAM'])
54
 
55
  # lancer l'interface
56
  demo.launch()
 
3
  import numpy as np
4
  import joblib
5
  from tensorflow.keras.preprocessing.sequence import pad_sequences
 
6
  # Fonction de prédiction pour le lstm
7
  def analyser_sentiment_lstm(tweet):
8
  sequence = tokenizer.texts_to_sequences([tweet])
 
12
  sentiment = "Positif" if prediction[0] >= 0.5 else "Négatif"
13
  return {sentiment: float(prediction[0]) if sentiment == "Positif" else 1 - float(prediction[0])}
14
 
 
 
 
 
 
 
 
15
 
16
  # Charger le modèle LSTM
17
  model = tf.keras.models.load_model("lstm_model.h5")
 
19
  # Charger le tokenizer utilisé pendant l'entraînement
20
  tokenizer = joblib.load('tokenizer.joblib')
21
 
 
 
 
22
  # Interface Gradio
23
  interface1 = gr.Interface(
24
  fn=analyser_sentiment_lstm,
25
  inputs=gr.Textbox(lines=3, placeholder="Entrez un tweet en français ici..."),
26
  outputs=gr.Label(num_top_classes=2),
27
  title="Analyse de Sentiment de Tweets",
28
+ description="Entrez un tweet en français pour obtenir son sentiment (positif, négatif).",
29
+ theme='shivi/calm_seafoam'
 
 
 
 
 
 
 
30
  )
31
 
32
 
 
 
 
33
 
34
  # lancer l'interface
35
  demo.launch()