bright1 commited on
Commit
5cc4dcb
1 Parent(s): 449d1c8

Readded files to hugging face

Browse files
Files changed (6) hide show
  1. .gitattributes +34 -0
  2. Dockerfile +26 -0
  3. README.md +10 -0
  4. app.py +104 -0
  5. requirements.txt +8 -0
  6. utils.py +48 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ WORKDIR /code
7
+
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ # Set up a new user named "user" with user ID 1000
13
+ RUN useradd -m -u 1000 user
14
+ # Switch to the "user" user
15
+ USER user
16
+ # Set home to the user's home directory
17
+ ENV HOME=/home/user \
18
+ PATH=/home/user/.local/bin:$PATH
19
+
20
+ # Set the working directory to the user's home directory
21
+ WORKDIR $HOME/app
22
+
23
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
24
+ COPY --chown=user . $HOME/app
25
+
26
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: My Second Docker App
3
+ emoji: 👁
4
+ colorFrom: yellow
5
+ colorTo: indigo
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ # from scipy.special import softmax
5
+ # import os
6
+ from utils import run_sentiment_analysis, preprocess
7
+ from transformers import AutoTokenizer, AutoConfig,AutoModelForSequenceClassification
8
+ import os
9
+ import time
10
+
11
+ # Requirements
12
+ model_path = "bright1/fine-tuned-distilbert-base-uncased"
13
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
14
+ config = AutoConfig.from_pretrained(model_path)
15
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
16
+
17
+ # dark_theme = set_theme()
18
+
19
+
20
+ st.set_page_config(
21
+ page_title="Tweet Analyzer",
22
+ page_icon="🤖",
23
+ initial_sidebar_state="expanded",
24
+ menu_items={
25
+ 'About': "# This is a header. This is an *extremely* cool app!"
26
+ }
27
+ )
28
+
29
+
30
+ my_expander = st.container()
31
+
32
+
33
+ # st.sidebar.selectbox('Menu', ['About', 'Model'])
34
+ with my_expander:
35
+
36
+ st.markdown("""
37
+ <style>
38
+ h1 {
39
+ text-align: center;
40
+ }
41
+ </style>
42
+ """, unsafe_allow_html=True)
43
+ st.title(':green[Covid-19 Vaccines Tweets Analyzer]')
44
+ st.sidebar.markdown("""
45
+ ## Demo App
46
+
47
+ This app analyzes your tweets on covid vaccines and classifies them us Neutral, Negative or Positive
48
+ """)
49
+ # my_expander.write('Container')
50
+ # create a three column layout
51
+
52
+ col1, col2, col3 = st.columns((1.6, 1,0.3))
53
+ # col2.markdown("""
54
+ # <p style= font-color:red>
55
+ # Results from Analyzer
56
+ # </p>
57
+ # """,unsafe_allow_html=True)
58
+ st.markdown("""
59
+ <style>
60
+ p {
61
+ font-color: blue;
62
+ }
63
+ </style>
64
+ """, unsafe_allow_html=True)
65
+ tweet = col1.text_area('Tweets to analyze',height=200, max_chars=520, placeholder='Write your Tweets here')
66
+ colA, colb, colc, cold = st.columns(4)
67
+ clear_button = colA.button(label='Clear', type='secondary', use_container_width=True)
68
+ submit_button = colb.button(label='Submit', type='primary', use_container_width=True)
69
+ empty_container = col2.container()
70
+ empty_container.text("Results from Analyzer")
71
+ empty_container2 = col3.container()
72
+ empty_container2.text('Scores')
73
+ text = preprocess(tweet)
74
+ results = run_sentiment_analysis(text=text, model=model, tokenizer=tokenizer)
75
+ if submit_button:
76
+ success_message = st.success('Success', icon="✅")
77
+
78
+ with empty_container:
79
+
80
+ neutral = st.progress(value=results['Neutral'], text='Neutral',)
81
+ negative = st.progress(value=results['Negative'], text='Negative')
82
+ positive = st.progress(value=results['Positive'], text='Positive')
83
+ with empty_container2:
84
+ st.markdown(
85
+ """
86
+ <style>
87
+ [data-testid="stMetricValue"] {
88
+ font-size: 20px;
89
+ }
90
+ </style>
91
+ """,
92
+ unsafe_allow_html=True,
93
+ )
94
+ neutral_score = st.metric(label='Score', value=round(results['Neutral'], 4), label_visibility='collapsed')
95
+ negative_score = st.metric(label='Score', value=round(results['Negative'], 4), label_visibility='collapsed')
96
+ positive_score = st.metric(label='Score', value=round(results['Positive'], 4), label_visibility='collapsed')
97
+ time.sleep(5)
98
+ success_message.empty()
99
+ # interpret_button = col2.button(label='Interpret',type='secondary', use_container_width=True)
100
+
101
+
102
+ # st.help()
103
+ # create a date input to receive date
104
+
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit==1.22.0
2
+ nltk==3.8.1
3
+ torch==2.0.0
4
+ datasets==2.12.0
5
+ numpy==1.22.4
6
+ pandas==1.5.3
7
+ scikit-learn==1.2.2
8
+ transformers==4.28.1
utils.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ from transformers import AutoTokenizer, AutoConfig,AutoModelForSequenceClassification
4
+ from scipy.special import softmax
5
+ import os
6
+
7
+
8
+
9
+ def check_csv(csv_file, data):
10
+ if os.path.isfile(csv_file):
11
+ data.to_csv(csv_file, mode='a', header=False, index=False, encoding='utf-8')
12
+ else:
13
+ history = data.copy()
14
+ history.to_csv(csv_file, index=False)
15
+
16
+ #Preprocess text
17
+ def preprocess(text):
18
+ new_text = []
19
+ for t in text.split(" "):
20
+ t = "@user" if t.startswith("@") and len(t) > 1 else t
21
+ t = "http" if t.startswith("http") else t
22
+ print(t)
23
+ new_text.append(t)
24
+ print(new_text)
25
+
26
+ return " ".join(new_text)
27
+
28
+ #Process the input and return prediction
29
+ def run_sentiment_analysis(text, tokenizer, model):
30
+ # save_text = {'tweet': text}
31
+ encoded_input = tokenizer(text, return_tensors = "pt") # for PyTorch-based models
32
+ output = model(**encoded_input)
33
+ scores_ = output[0][0].detach().numpy()
34
+ scores_ = softmax(scores_)
35
+
36
+ # Format output dict of scores
37
+ labels = ["Negative", "Neutral", "Positive"]
38
+ scores = {l:float(s) for (l,s) in zip(labels, scores_) }
39
+ # save_text.update(scores)
40
+ # user_data = {key: [value] for key,value in save_text.items()}
41
+ # data = pd.DataFrame(user_data,)
42
+ # check_csv('history.csv', data)
43
+ # hist_df = pd.read_csv('history.csv')
44
+ return scores
45
+
46
+
47
+
48
+