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() | |