Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,16 @@
|
|
| 1 |
-
import
|
| 2 |
-
import transformers
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Chargement du modèle de classification de sentiment
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
@spaces.GPU
|
| 10 |
-
|
| 11 |
classifier = pipeline("sentiment-analysis")
|
| 12 |
|
| 13 |
# Fonction pour prédire le sentiment d'un post
|
| 14 |
-
|
| 15 |
def predict_sentiment(post):
|
| 16 |
result = classifier(post)
|
| 17 |
sentiment = result[0]['label']
|
| 18 |
return sentiment
|
| 19 |
|
| 20 |
-
|
| 21 |
# Fonction de génération de texte basée sur le sentiment
|
| 22 |
-
|
| 23 |
def generate_response(prompt):
|
| 24 |
sentiment = predict_sentiment(prompt)
|
| 25 |
if sentiment == 'POSITIVE':
|
|
@@ -29,7 +20,5 @@ def generate_response(prompt):
|
|
| 29 |
else:
|
| 30 |
return "Merci pour vos commentaires."
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Chargement du modèle de classification de sentiment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
classifier = pipeline("sentiment-analysis")
|
| 6 |
|
| 7 |
# Fonction pour prédire le sentiment d'un post
|
|
|
|
| 8 |
def predict_sentiment(post):
|
| 9 |
result = classifier(post)
|
| 10 |
sentiment = result[0]['label']
|
| 11 |
return sentiment
|
| 12 |
|
|
|
|
| 13 |
# Fonction de génération de texte basée sur le sentiment
|
|
|
|
| 14 |
def generate_response(prompt):
|
| 15 |
sentiment = predict_sentiment(prompt)
|
| 16 |
if sentiment == 'POSITIVE':
|
|
|
|
| 20 |
else:
|
| 21 |
return "Merci pour vos commentaires."
|
| 22 |
|
| 23 |
+
# Interface de chatbot utilisant Gradio
|
| 24 |
+
gr.Interface(fn=generate_response, inputs="text", outputs="text").launch()
|
|
|
|
|
|