ihsan66 commited on
Commit
d8bc695
1 Parent(s): bde8b21

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py CHANGED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ from transformers import pipeline, TFAutoModelForSequenceClassification, AutoTokenizer
4
+ from datasets import load_dataset
5
+ import pandas as pd
6
+
7
+ st.set_page_config(layout="wide")
8
+
9
+ # Load dataset
10
+ @st.cache_resource
11
+ def load_data():
12
+ dataset = load_dataset("WhiteAngelss/Turkce-Duygu-Analizi-Dataset")
13
+ return dataset
14
+
15
+ dataset = load_data()
16
+ st.title("Sentiment Analysis with Turkish Dataset")
17
+
18
+ # Show dataset examples
19
+ st.subheader("Sample Data")
20
+ sample_df = pd.DataFrame(dataset['train'])
21
+ st.write(sample_df.head())
22
+
23
+ # Set up model
24
+ model_list = ['WhiteAngelss/entity-word-sentiment-analysis']
25
+ st.sidebar.header("Select Sentiment Analysis Model")
26
+ model_checkpoint = st.sidebar.radio("", model_list)
27
+
28
+ st.sidebar.write("For details of models: 'https://huggingface.co/WhiteAngelss/entity-word-sentiment-analysis'")
29
+ st.sidebar.write("")
30
+
31
+ st.subheader("Select Text Input Method")
32
+ input_method = st.radio("", ('Select from Examples', 'Write or Paste New Text'))
33
+
34
+ if input_method == 'Select from Examples':
35
+ example_texts = dataset['train']['text'][:5] # Sample examples from the dataset
36
+ selected_text = st.selectbox('Select Text from List', example_texts)
37
+ st.subheader("Text to Analyze")
38
+ input_text = st.text_area("Selected Text", selected_text, height=128, max_chars=None)
39
+ elif input_method == "Write or Paste New Text":
40
+ st.subheader("Text to Analyze")
41
+ input_text = st.text_area('Write or Paste Text Below', value="", height=128, max_chars=None)
42
+
43
+ @st.cache_resource
44
+ def setModel(model_checkpoint):
45
+ model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint)
46
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
47
+ return pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
48
+
49
+ Run_Button = st.button("Run", key=None)
50
+
51
+ if Run_Button and input_text:
52
+ sentiment_pipeline = setModel(model_checkpoint)
53
+ output = sentiment_pipeline(input_text)
54
+
55
+ st.subheader("Sentiment Analysis Results")
56
+ df = pd.DataFrame(output)
57
+ st.dataframe(df)
58
+
59
+ # Display the sentiment in a more user-friendly format
60
+ sentiment = output[0]['label']
61
+ score = output[0]['score']
62
+ st.write(f"Sentiment: {sentiment} (Score: {score:.2f})")