Vineedhar commited on
Commit
0b1144c
·
verified ·
1 Parent(s): 37c7be7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
3
+ import tensorflow as tf
4
+ tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
5
+
6
+ # Load pre-trained model and tokenizer
7
+ saved_directory = "models/cardiffnlp/twitter-xlm-roberta-base-sentiment"
8
+ tokenizer = AutoTokenizer.from_pretrained(saved_directory)
9
+ model = AutoModelForSequenceClassification.from_pretrained(saved_directory)
10
+ nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
11
+
12
+ # Define function to analyze sentiment
13
+ def analyze_sentiment(text):
14
+ result = nlp(text)
15
+ return result[0]['label'], result[0]['score']
16
+
17
+ # Streamlit UI
18
+ st.set_page_config(page_title="Sentiment Analysis", layout="wide")
19
+ col1, col2 = st.columns([6, 1]) # Divide the screen into two columns
20
+
21
+
22
+
23
+ with col2: # Right-aligned column for the logo
24
+ st.image("https://huggingface.co/spaces/orYx-models/Leadership-sentiment-analyzer/resolve/main/oryx_logo%20(2).png", width=200, use_column_width=False) # Provide the path to your company logo
25
+
26
+ with col1: # Main content area
27
+
28
+ # Text titles below the text box
29
+ st.markdown("This sentiment analysis model serves as a testing prototype, specifically developed for LDS to assess the variability and precision of OrYx Models' sentiment analysis tool.")
30
+ st.markdown(" ")
31
+ st.markdown("All feedback gathered from LDS, including both structured and unstructured data, will be incorporated into the model to enhance its domain specificity and maximize accuracy.")
32
+
33
+
34
+ st.title("Sentiment Analysis Prototype Tool by orYx Models")
35
+ user_input = st.text_area("Enter text to analyze:", height=200)
36
+
37
+ submit_button = st.button("Analyze")
38
+
39
+ if submit_button and user_input:
40
+ sentiment, score = analyze_sentiment(user_input)
41
+ st.markdown("Sentiment Analysis Result:")
42
+ st.write(f"Sentiment: {sentiment}")
43
+ st.write(f"Confidence: {score*100:.2f}%")