Justin-J commited on
Commit
880ccad
·
1 Parent(s): abc410f

Added my Project Files, Deployed my App

Browse files
Files changed (2) hide show
  1. app.py +67 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import transformers
3
+ import torch
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
+
6
+ # Load the model and tokenizer
7
+ tokenizer = AutoTokenizer.from_pretrained("ikoghoemmanuell/finetuned_sentiment_modell")
8
+ model = AutoModelForSequenceClassification.from_pretrained("ikoghoemmanuell/finetuned_sentiment_modell")
9
+
10
+ # Define the function for sentiment analysis
11
+ @st.cache_resource
12
+ def predict_sentiment(text):
13
+ # Load the pipeline.
14
+ pipeline = transformers.pipeline("sentiment-analysis")
15
+
16
+ # Predict the sentiment.
17
+ prediction = pipeline(text)
18
+ sentiment = prediction[0]["label"]
19
+ score = prediction[0]["score"]
20
+
21
+ return sentiment, score
22
+
23
+ # Setting the page configurations
24
+ st.set_page_config(
25
+ page_title="Sentiment Analysis App",
26
+ page_icon=":smile:",
27
+ layout="wide",
28
+ initial_sidebar_state="auto",
29
+ )
30
+
31
+ # Add description and title
32
+ st.write("""
33
+ # How Positive or Negative is your Text?
34
+ Enter some text and we'll tell you if it has a positive, negative, or neutral sentiment!
35
+ """)
36
+
37
+
38
+ # Add image
39
+ image = st.image("https://i0.wp.com/thedatascientist.com/wp-content/uploads/2018/10/sentiment-analysis.png", width=400)
40
+
41
+ # Get user input
42
+ text = st.text_input("Enter some text here:")
43
+
44
+ # Define the CSS style for the app
45
+ st.markdown(
46
+ """
47
+ <style>
48
+ body {
49
+ background-color: #f5f5f5;
50
+ }
51
+ h1 {
52
+ color: #4e79a7;
53
+ }
54
+ </style>
55
+ """,
56
+ unsafe_allow_html=True
57
+ )
58
+
59
+ # Show sentiment output
60
+ if text:
61
+ sentiment, score = predict_sentiment(text)
62
+ if sentiment == "Positive":
63
+ st.success(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
64
+ elif sentiment == "Negative":
65
+ st.error(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
66
+ else:
67
+ st.warning(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers