Test1 / app.py
bistdude's picture
Update app.py
90fa538 verified
raw
history blame
732 Bytes
import torch
import tensorflow as tf
import flax
import gradio as gr
from transformers import pipeline
sentiment_pipeline= pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
# texts = ["Hugging face? weired, but memorable.", "I am despirate"]
# results = sentiment_pipeline(texts)
# for text, results in zip(texts, results):
# print(f"Text: {text}")
# print(f"Sentiment: {result['label']}, Score: {result['score']:.4f}\n")
def predict_sentiment(text):
result = sentiment_pipeline(text)
return result[0]['label'], result[0]['score']
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs = ["label","number"])
if __name__ == "__main__":
iface.launch()