File size: 1,361 Bytes
342796f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Load model and tokenizer from Hugging Face
model_name = "visalkao/sentiment-analysis-french"  # Replace with your model's name
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Prediction function
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:
    # Title and description
    gr.Markdown("## Analyse du sentiment des avis des clients")
    gr.Markdown("Écrire un avis sur un produit.")
    
    # Input row
    with gr.Row():
        with gr.Column(elem_classes="centered-col"):
            input_text = gr.Textbox(label="Input", placeholder="Avis...")
    
    # Output row
    with gr.Row():
        with gr.Column(elem_classes="centered-col"):
            output_text = gr.Textbox(label="Output")
    
    # Submit button (full-width by default)
    btn = gr.Button("Envoyer")
    btn.click(fn=classify_email, inputs=input_text, outputs=output_text)

demo.launch()