Vineedhar's picture
Update app.py
850932c verified
raw
history blame
2.07 kB
# -*- 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)
# 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}%")