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