ynp3 commited on
Commit
6ae0692
·
1 Parent(s): 64c1ccd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ import seaborn as sns
6
+ import transformers
7
+ from transformers import pipeline
8
+
9
+ # Set up sentiment analysis pipeline
10
+ model_names = ['nlptown/bert-base-multilingual-uncased-sentiment',
11
+ 'cardiffnlp/twitter-roberta-base-sentiment',
12
+ 'distilbert-base-uncased-finetuned-sst-2-english',
13
+ 'nlptown/roberta-base-sentiment-english']
14
+ models = {}
15
+ for model_name in model_names:
16
+ models[model_name] = pipeline('sentiment-analysis', model=model_name)
17
+
18
+ # Set up Streamlit app
19
+ st.title("Sentiment Analysis App")
20
+
21
+ # User input
22
+ text_input = st.text_input("Enter text to analyze:")
23
+
24
+ if text_input:
25
+ # Analyze text with each model and store results in a DataFrame
26
+ results = []
27
+ for model_name, model in models.items():
28
+ result = model(text_input)[0]
29
+ results.append({'Model': model_name, 'Score': result['score'], 'Label': result['label']})
30
+ results_df = pd.DataFrame(results)
31
+
32
+ # Display results in a table
33
+ st.write("Results:")
34
+ st.table(results_df)
35
+
36
+ # Plot results in a bar chart
37
+ fig, ax = plt.subplots(figsize=(8, 6))
38
+ sns.barplot(x='Model', y='Score', hue='Label', data=results_df, ax=ax)
39
+ ax.set_title('Sentiment Analysis Results')
40
+ ax.set_ylabel('Score')
41
+ ax.set_xlabel('Model')
42
+   st.pyplot(fig)