Commit
•
48768d3
0
Parent(s):
Duplicate from ellyothim/First_shot_gradio_covid_sentiment_analysis
Browse filesCo-authored-by: Othim <[email protected]>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +57 -0
- requirements.txt +6 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: First Shot Gradio Covid Sentiment Analysis
|
3 |
+
emoji: 🔥
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.38.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: ellyothim/First_shot_gradio_covid_sentiment_analysis
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import AutoModelForSequenceClassification
|
4 |
+
from transformers import TFAutoModelForSequenceClassification
|
5 |
+
from transformers import AutoTokenizer, AutoConfig
|
6 |
+
import numpy as np
|
7 |
+
from scipy.special import softmax
|
8 |
+
|
9 |
+
|
10 |
+
# setting up the requiremnts
|
11 |
+
|
12 |
+
model_path = f"mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained('mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis')
|
14 |
+
config = AutoConfig.from_pretrained(model_path)
|
15 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
16 |
+
|
17 |
+
# Preprocess text (username and link placeholders)
|
18 |
+
def preprocess(text):
|
19 |
+
new_text = []
|
20 |
+
for t in text.split(" "):
|
21 |
+
t = '@user' if t.startswith('@') and len(t) > 1 else t
|
22 |
+
t = 'http' if t.startswith('http') else t
|
23 |
+
new_text.append(t)
|
24 |
+
return " ".join(new_text)
|
25 |
+
|
26 |
+
# Defining the main function
|
27 |
+
def sentiment_analysis(text):
|
28 |
+
text = preprocess(text)
|
29 |
+
|
30 |
+
# PyTorch-based models
|
31 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
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 |
+
|
40 |
+
return scores
|
41 |
+
|
42 |
+
welcome_message = "Welcome to Team Paris tweets first shot Sentimental Analysis App 😃 😃 😃 😃 "
|
43 |
+
demo = gr.Interface(
|
44 |
+
fn=sentiment_analysis,
|
45 |
+
inputs=gr.Textbox(placeholder="Write your tweet here..."),
|
46 |
+
outputs="label",
|
47 |
+
interpretation="default",
|
48 |
+
examples=[["This is wonderful!"]],
|
49 |
+
title=welcome_message,
|
50 |
+
description=("This is a sentimental analysis app built by fine tuning a model trained on financial news sentiment, we leverage what the model has learnt, /n, and fine tune it on twitter comments . The eval_loss of our model is 0.785")
|
51 |
+
)
|
52 |
+
demo.launch()
|
53 |
+
# def greet(name):
|
54 |
+
# return "Hello " + name + "!!"
|
55 |
+
|
56 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
57 |
+
# iface.launch(inline = False)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
numpy
|
4 |
+
gradio
|
5 |
+
scipy>=1.6.0
|
6 |
+
|