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