-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (23 loc) · 875 Bytes
/
app.py
File metadata and controls
28 lines (23 loc) · 875 Bytes
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
import gradio as gr
from transformers import pipeline
import os
# Charger le modèle (identique à celui de ton API)
MODEL_NAME = os.getenv("HF_MODEL", "distilbert-base-uncased-finetuned-sst-2-english")
sentiment_pipe = pipeline("sentiment-analysis", model=MODEL_NAME)
# Fonction de prédiction
def predict_sentiment(text):
result = sentiment_pipe(text)[0]
label = "positive" if result["label"].upper().startswith("POS") else "negative"
confidence = float(result["score"])
return f"Label: {label}, Confidence: {confidence:.4f}"
# Interface Gradio
iface = gr.Interface(
fn=predict_sentiment,
inputs=gr.Textbox(lines=3, placeholder="Entrez votre texte ici..."),
outputs="text",
title="Sentiment Analysis Demo",
description=f"Modèle: {MODEL_NAME}"
)
# Lancer l'interface en local
if __name__ == "__main__":
iface.launch(share=True)