File size: 681 Bytes
f3da54c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()