File size: 4,019 Bytes
161513a
 
 
 
 
 
 
 
 
 
 
 
89796f5
 
 
 
 
 
 
 
568454a
161513a
2c62ca4
161513a
 
 
 
 
 
 
 
 
 
 
 
 
b9b5d54
 
161513a
b9b5d54
161513a
 
850932c
 
 
 
 
 
 
161513a
 
 
b9b5d54
161513a
 
 
 
 
 
 
b9b5d54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 19 16:58:55 2024

@author: phonoDS
"""

import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

# LICENSE.streamlit.Apachev2 	- 	Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) (https://github.com/streamlit/streamlit/blob/develop/LICENSE)

# LICENSE.tranformers.Apachev2	- 	Copyright 2020 The HuggingFace Team. All rights reserved. (https://github.com/huggingface/huggingface_hub/blob/main/LICENSE)

# LICESNE.tensorflow.Apachev2	- 	Copyright 2015 The TensorFlow Authors. All Rights Reserved. (https://github.com/tensorflow/tensorflow/blob/master/LICENSE)

# LICENSE.Roberta.Apachev2 		-	@InProceedings{barbieri-espinosaanke-camachocollados:2022:LREC,author    = {Barbieri, Francesco  and  Espinosa Anke, Luis  and  Camacho-Collados, Jose}, title     = {XLM-T: Multilingual Language Models in Twitter for Sentiment Analysis and Beyond}, booktitle      = {Proceedings of the Language Resources and Evaluation Conference}, month          = {June}, year           = {2022}, address        = {Marseille, France}, publisher      = {European Language Resources Association}, pages     = {258--266}, abstract  = {Language models are ubiquitous in current NLP, and their multilingual capacity has recently attracted considerable attention. However, current analyses have almost exclusively focused on (multilingual variants of) standard benchmarks, and have relied on clean pre-training and task-specific corpora as multilingual signals. In this paper, we introduce XLM-T, a model to train and evaluate multilingual language models in Twitter. In this paper we provide: (1) a new strong multilingual baseline consisting of an XLM-R (Conneau et al. 2020) model pre-trained on millions of tweets in over thirty languages, alongside starter code to subsequently fine-tune on a target task; and (2) a set of unified sentiment analysis Twitter datasets in eight different languages and a XLM-T model trained on this dataset.}, url       = {https://aclanthology.org/2022.lrec-1.27}} (https://github.com/cardiffnlp/xlm-t/blob/main/LICENSE)


# Load pre-trained model and tokenizer
saved_directory = "orYx-models/finetuned-roberta-leadership-sentiment-analysis"
tokenizer = AutoTokenizer.from_pretrained(saved_directory)
model = AutoModelForSequenceClassification.from_pretrained(saved_directory)
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)

# Define function to analyze sentiment
def analyze_sentiment(text):
    result = nlp(text)
    return result[0]['label'], result[0]['score']

# Streamlit UI
st.set_page_config(page_title="Sentiment Analysis", layout="wide")
col1, col2 = st.columns([6, 1])  # Divide the screen into two columns



with col2:  # Right-aligned column for the logo
    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

with col1:  # Main content area

    # Text titles below the text box
    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.")
    st.markdown(" ")     
    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.")

    
    st.title("Sentiment Analysis Prototype Tool by orYx Models")
    user_input = st.text_area("Enter text to analyze:", height=200)
    
    submit_button = st.button("Analyze")

    if submit_button and user_input:
        sentiment, score = analyze_sentiment(user_input)
        st.markdown("Sentiment Analysis Result:")
        st.write(f"Sentiment:  {sentiment}")
        st.write(f"Confidence:  {score*100:.2f}%")