Spaces:
Sleeping
Sleeping
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() | |