slachitoff commited on
Commit
a61227e
1 Parent(s): 73ae063

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pip._internal
2
+
3
+ print("Installing required libraries...")
4
+ pip._internal.main(["install", "-q", "transformers", "torch"])
5
+
6
+ from transformers import pipeline, AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
7
+
8
+ import streamlit as st
9
+ st.title("Sentiment Analysis App")
10
+ models = [
11
+ "distilbert-base-uncased-finetuned-sst-2-english",
12
+ "cardiffnlp/twitter-roberta-base-sentiment",
13
+ "roberta-base-openai-detector",
14
+ "xlnet-base-cased",
15
+ "ProsusAI/finbert",
16
+ "roberta-large-mnli",
17
+ "roberta-large-openai-detector",
18
+ "bhadresh-savani/distilbert-base-uncased-emotion",
19
+ "nlptown/bert-base-multilingual-uncased-sentiment",
20
+ "Seethal/sentiment_analysis_generic_dataset",
21
+ "mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis",
22
+ "ahmedrachid/FinancialBERT-Sentiment-Analysis",
23
+ ]
24
+ defaultModelName = models[0]
25
+ modelName = st.selectbox("Select a model", options=models, index=models.index(defaultModelName))
26
+ sampleText = """Once there were brook trouts in the streams in the mountains.
27
+ You could see them standing in the amber current where the white edges of their fins wimpled softly in the flow.
28
+ They smelled of moss in your hand. Polished and muscular and torsional.
29
+ On their backs were vermiculate patterns that were maps of the world in its becoming.
30
+ Maps and mazes. Of a thing which could not be put back. Not be made right again.
31
+ In the deep glens where they lived all things were older than man and they hummed of mystery."""
32
+ textInput = st.text_area("Enter some text to analyze", value=sampleText, height=200)
33
+ submitButton = st.button("Analyze")
34
+
35
+ tokenizer = AutoTokenizer.from_pretrained(modelName)
36
+ model = AutoModelForSequenceClassification.from_pretrained(modelName)
37
+ sentimentPipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
38
+
39
+ if submitButton:
40
+ if not textInput.strip():
41
+ st.write("Please enter some text to analyze.")
42
+ else:
43
+ results = sentimentPipeline(textInput)
44
+ st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}")