|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
|
|
|
model_name = "visalkao/sentiment-analysis-french" |
|
model = AutoModelForSequenceClassification.from_pretrained(model_name) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
|
|
|
def classify_email(text): |
|
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True) |
|
outputs = model(**inputs) |
|
predictions = outputs.logits.argmax(axis=-1).item() |
|
return "Avis négatif" if predictions == 0 else "Avis positif" |
|
|
|
|
|
css = """ |
|
.centered-col { |
|
margin: 0 auto; |
|
width: 30%; |
|
} |
|
""" |
|
with gr.Blocks(css=css) as demo: |
|
|
|
gr.Markdown("## Analyse du sentiment des avis des clients") |
|
gr.Markdown("Écrire un avis sur un produit.") |
|
|
|
|
|
with gr.Row(): |
|
with gr.Column(elem_classes="centered-col"): |
|
input_text = gr.Textbox(label="Input", placeholder="Avis...") |
|
|
|
|
|
with gr.Row(): |
|
with gr.Column(elem_classes="centered-col"): |
|
output_text = gr.Textbox(label="Output") |
|
|
|
|
|
btn = gr.Button("Envoyer") |
|
btn.click(fn=classify_email, inputs=input_text, outputs=output_text) |
|
|
|
demo.launch() |
|
|