|
pip install transformers |
|
|
|
.\venv\Scripts\activate |
|
|
|
import streamlit as st |
|
from transformers import pipeline, TFAutoModelForSequenceClassification, AutoTokenizer |
|
from datasets import load_dataset |
|
import pandas as pd |
|
|
|
st.set_page_config(layout="wide") |
|
|
|
|
|
@st.cache_resource |
|
def load_data(): |
|
dataset = load_dataset("WhiteAngelss/Turkce-Duygu-Analizi-Dataset") |
|
return dataset |
|
|
|
dataset = load_data() |
|
st.title("Sentiment Analysis with Turkish Dataset") |
|
|
|
|
|
st.subheader("Sample Data") |
|
sample_df = pd.DataFrame(dataset['train']) |
|
st.write(sample_df.head()) |
|
|
|
|
|
model_list = ['WhiteAngelss/entity-word-sentiment-analysis'] |
|
st.sidebar.header("Select Sentiment Analysis Model") |
|
model_checkpoint = st.sidebar.radio("", model_list) |
|
|
|
st.sidebar.write("For details of models: 'https://huggingface.co/WhiteAngelss/entity-word-sentiment-analysis'") |
|
st.sidebar.write("") |
|
|
|
st.subheader("Select Text Input Method") |
|
input_method = st.radio("", ('Select from Examples', 'Write or Paste New Text')) |
|
|
|
if input_method == 'Select from Examples': |
|
example_texts = dataset['train']['text'][:5] |
|
selected_text = st.selectbox('Select Text from List', example_texts) |
|
st.subheader("Text to Analyze") |
|
input_text = st.text_area("Selected Text", selected_text, height=128, max_chars=None) |
|
elif input_method == "Write or Paste New Text": |
|
st.subheader("Text to Analyze") |
|
input_text = st.text_area('Write or Paste Text Below', value="", height=128, max_chars=None) |
|
|
|
@st.cache_resource |
|
def setModel(model_checkpoint): |
|
model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint) |
|
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint) |
|
return pipeline('sentiment-analysis', model=model, tokenizer=tokenizer) |
|
|
|
Run_Button = st.button("Run") |
|
|
|
if Run_Button and input_text: |
|
sentiment_pipeline = setModel(model_checkpoint) |
|
output = sentiment_pipeline(input_text) |
|
|
|
st.subheader("Sentiment Analysis Results") |
|
df = pd.DataFrame(output) |
|
st.dataframe(df) |
|
|
|
|
|
sentiment = output[0]['label'] |
|
score = output[0]['score'] |
|
st.write(f"Sentiment: {sentiment} (Score: {score:.2f})") |
|
|