Monit & Visal
commited on
Commit
·
342796f
1
Parent(s):
dbece43
Add app
Browse files- app.py +42 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
|
4 |
+
# Load model and tokenizer from Hugging Face
|
5 |
+
model_name = "visalkao/sentiment-analysis-french" # Replace with your model's name
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Prediction function
|
10 |
+
def classify_email(text):
|
11 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
12 |
+
outputs = model(**inputs)
|
13 |
+
predictions = outputs.logits.argmax(axis=-1).item()
|
14 |
+
return "Avis négatif" if predictions == 0 else "Avis positif"
|
15 |
+
|
16 |
+
|
17 |
+
css = """
|
18 |
+
.centered-col {
|
19 |
+
margin: 0 auto;
|
20 |
+
width: 30%;
|
21 |
+
}
|
22 |
+
"""
|
23 |
+
with gr.Blocks(css=css) as demo:
|
24 |
+
# Title and description
|
25 |
+
gr.Markdown("## Analyse du sentiment des avis des clients")
|
26 |
+
gr.Markdown("Écrire un avis sur un produit.")
|
27 |
+
|
28 |
+
# Input row
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column(elem_classes="centered-col"):
|
31 |
+
input_text = gr.Textbox(label="Input", placeholder="Avis...")
|
32 |
+
|
33 |
+
# Output row
|
34 |
+
with gr.Row():
|
35 |
+
with gr.Column(elem_classes="centered-col"):
|
36 |
+
output_text = gr.Textbox(label="Output")
|
37 |
+
|
38 |
+
# Submit button (full-width by default)
|
39 |
+
btn = gr.Button("Envoyer")
|
40 |
+
btn.click(fn=classify_email, inputs=input_text, outputs=output_text)
|
41 |
+
|
42 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|