classification / app.py
alex-abb's picture
Update app.py
e0eb25c verified
raw
history blame
661 Bytes
import gradio as gr
from transformers import pipeline
import spaces
classifier = pipeline("sentiment-analysis")
@spaces.GPU
def predict_sentiment(post):
result = classifier(post)
sentiment = result[0]['label']
return sentiment
def generate_response(prompt):
sentiment = predict_sentiment(prompt)
if sentiment == 'POSITIVE':
return "Je suis content de discuter avec vous!"
elif sentiment == 'NEGATIVE':
return "Je suis désolé que vous ressentiez cela. Comment puis-je vous aider?"
else:
return "Merci pour vos commentaires."
gr.Interface(fn=generate_response, inputs="text", outputs="text").launch()