Spaces:
Runtime error
Runtime error
| import pip._internal | |
| print("Installing required libraries...") | |
| pip._internal.main(["install", "-q", "transformers", "torch"]) | |
| from transformers import pipeline, AutoTokenizer, AutoConfig, AutoModelForSequenceClassification | |
| import streamlit as st | |
| st.title("Sentiment Analysis App") | |
| models = [ | |
| "distilbert-base-uncased-finetuned-sst-2-english", | |
| "cardiffnlp/twitter-roberta-base-sentiment", | |
| "roberta-base-openai-detector", | |
| "xlnet-base-cased", | |
| "ProsusAI/finbert", | |
| "roberta-large-mnli", | |
| "roberta-large-openai-detector", | |
| "bhadresh-savani/distilbert-base-uncased-emotion", | |
| "nlptown/bert-base-multilingual-uncased-sentiment", | |
| "Seethal/sentiment_analysis_generic_dataset", | |
| "mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis", | |
| "ahmedrachid/FinancialBERT-Sentiment-Analysis", | |
| ] | |
| defaultModelName = models[0] | |
| modelName = st.selectbox("Select a model", options=models, index=models.index(defaultModelName)) | |
| sampleText = """Once there were brook trouts in the streams in the mountains. | |
| You could see them standing in the amber current where the white edges of their fins wimpled softly in the flow. | |
| They smelled of moss in your hand. Polished and muscular and torsional. | |
| On their backs were vermiculate patterns that were maps of the world in its becoming. | |
| Maps and mazes. Of a thing which could not be put back. Not be made right again. | |
| In the deep glens where they lived all things were older than man and they hummed of mystery.""" | |
| textInput = st.text_area("Enter some text to analyze", value=sampleText, height=200) | |
| submitButton = st.button("Analyze") | |
| tokenizer = AutoTokenizer.from_pretrained(modelName) | |
| model = AutoModelForSequenceClassification.from_pretrained(modelName) | |
| sentimentPipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) | |
| if submitButton: | |
| if not textInput.strip(): | |
| st.write("Please enter some text to analyze.") | |
| else: | |
| results = sentimentPipeline(textInput) | |
| st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}") | |