Spaces:
Runtime error
Runtime error
Commit ·
b97ac1a
1
Parent(s): 1c2b333
Update app.py
Browse files123456789101112131415161718192021# app.pyimport streamlit as stfrom transformers import pipelinefrom textblob import TextBlobpipe = pipeline('sentiment-analysis')st.title("Hugging Face Sentiment Analysis Spaces Example")st.subheader("What framework would you like to use for Sentiment Analysis")#Picking what NLP task you want to dooption = st.selectbox('Framework',('Transformers', 'TextBlob')) #option is stored in this variable#Textbox for text user is enteringst.subheader("Enter the text you'd like to analyze.")text = st.text_input('Enter text') #text is stored in this variableif option == 'Transformers':out = pipe(text)else:out = TextBlob(text)out = out.sentimentst.write("Sentiment of Text: ")st.write(out)1234567891011121314# app.pyimport gradio as grfrom transformers import pipelinefrom transformers import AutoTokenizer, AutoModelForSequenceClassification#Defining the classify function which takes text as input and returns the label of the sentimentdef classify(text):# Initializing the pipeline for sentiment analysiscls = pipeline('text-classification', model='RJuro/dk_emotion_bert_in_class')# Predicting the sentiment label for the input textreturn cls(text)[0]['label']#Creating the Gradio interface with input textbox and output textgr.Interface(fn=classify, inputs=["textbox"], outputs="text").launch()
app.py+10-17