Spaces:
Runtime error
Runtime error
EnzoBustos
commited on
Commit
•
2229429
1
Parent(s):
3da8840
Update functions of app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
from textblob import TextBlob
|
2 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
3 |
from transformers import pipeline
|
|
|
4 |
import streamlit as st
|
5 |
|
6 |
def translate_text(text):
|
7 |
blob = TextBlob(text)
|
8 |
return str(blob.translate(from_lang="pt", to="en"))
|
9 |
|
10 |
-
def sentiment_classification(sentence):
|
11 |
-
sid_obj = SentimentIntensityAnalyzer()
|
12 |
|
13 |
-
sentiment_dict =
|
14 |
negative = sentiment_dict['neg']
|
15 |
neutral = sentiment_dict['neu']
|
16 |
positive = sentiment_dict['pos']
|
@@ -27,49 +27,78 @@ def sentiment_classification(sentence):
|
|
27 |
|
28 |
return overall_sentiment, sentiment_dict['compound']
|
29 |
|
30 |
-
def theme_classification(text):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
52 |
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
header = st.container()
|
56 |
model = st.container()
|
|
|
57 |
|
58 |
with st.sidebar:
|
59 |
st.markdown("# Lorem Ipsum\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sapien tortor, suscipit quis ornare ut, laoreet vitae nisi. Mauris quis consectetur risus, non blandit mauris. Sed ut odio tempor, ullamcorper leo eu, mollis eros. Curabitur pretium sollicitudin sapien, vel mattis augue convallis quis. Suspendisse eleifend turpis non nunc gravida, aliquet hendrerit orci viverra. Sed aliquet, nunc eu posuere tempor, libero ex dignissim velit, ut ultricies erat felis at urna. Proin metus augue, commodo in faucibus sed, aliquet ac eros. Nullam turpis leo, dictum eu tellus a, aliquam egestas velit. Suspendisse cursus augue a sem dapibus, eu faucibus nisl ultrices. Cras tortor ipsum, luctus vitae tincidunt id, dapibus id justo. Sed mi nunc, tempor eu iaculis in, tristique cursus massa. Integer metus felis, pulvinar ut aliquam ut, consectetur in nulla.")
|
60 |
|
61 |
with header:
|
62 |
st.title("IC 2022 Classificação de Dados Financeiros")
|
|
|
63 |
|
64 |
with model:
|
65 |
st.header("Modelo para Tradução e Classificação!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
if text:
|
70 |
-
text_en = translate_text(text)
|
71 |
-
st.write("Translation: {}".format(text_en))
|
72 |
-
sentiment = sentiment_classification(text_en)
|
73 |
-
st.write("Sentiment: {} - {}".format(sentiment[0], sentiment[1]))
|
74 |
-
theme = theme_classification(text_en)
|
75 |
-
st.write("Theme: {}".format(theme))
|
|
|
1 |
from textblob import TextBlob
|
2 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
3 |
from transformers import pipeline
|
4 |
+
import re
|
5 |
import streamlit as st
|
6 |
|
7 |
def translate_text(text):
|
8 |
blob = TextBlob(text)
|
9 |
return str(blob.translate(from_lang="pt", to="en"))
|
10 |
|
11 |
+
def sentiment_classification(sentence, vader_object):
|
|
|
12 |
|
13 |
+
sentiment_dict = vader_object.polarity_scores(sentence)
|
14 |
negative = sentiment_dict['neg']
|
15 |
neutral = sentiment_dict['neu']
|
16 |
positive = sentiment_dict['pos']
|
|
|
27 |
|
28 |
return overall_sentiment, sentiment_dict['compound']
|
29 |
|
30 |
+
def theme_classification(text, text_classifier):
|
31 |
+
if re.search(r"/Biomm|Nortcquimica|Ourofino|Alliar|Dasa|Fleury|Hapvida|Ihpardini|Kora Saude|Mater Dei|Odontoprev|Oncoclinicas|Qualicorp |Rede D Or|Baumer|Lifemed|Blau|D1000vfarma|Dimed|Hypera|Pague Menos|Profarma|Raiadrogasil|Viveo|Drogaraia|Ultrafarma|Drogasil|Raia/gm", text):
|
32 |
+
return "Health"
|
33 |
+
elif re.search(r"/Aura 360|Bradespar|Cba|Csnmineracao|Litel|Litela|Mmx Miner|Vale|Ferbasa|Gerdau|Gerdau Met|Sid Nacional|Usiminas|Mangels Indl|Panatlantica|Tekno|Paranapanema|Braskem|Dexxos Par|Fer Heringer|Nutriplant|Vittia|Cristal|Unipar|Dexco|Eucatex|Klabin|Melhor Sp|Suzano Hold|Suzano|Irani|Metal Iguacu|Sansuy|Eternit|Haga|Portobello|Azevedo|Sondotecnica|Tecnosolo|Embraer|Fras-le|Marcopolo|Randon Part|Recrusul|Riosulense|Tupy|Wetzel S\/a|Schulz|Weg|Aco Altona|Aeris|Armac|Bardella|Inepar|Kepler Weber|Metalfrio|Mills|Nordon Met|Pratica|Romi|Metisa|Stara|Taurus Armas|Azul|Gol|All Norte|All Paulista|Fer C Atlant|Mrs Logist|Rumo|Hidrovias|Log-in|Trevisa|Jsl|Tegma|Autoban|Ccr Sa|Conc Raposo|Conc Rio Ter|Ecopistas|Ecorodovias|Ecovias|Rod Colinas|Rod Tiete|Rt Bandeiras|Triangulosol|Triunfo Part|Viaoeste|Gruairport|Hmobi S.a|Invepar|Porto Vm|Salus Infra|Santos Brp|Wilson Sons|Atmasa|Bbmlogistica|Dtcom-direct|Estapar|Flex|Gps|Priner|Sequoia Log|Valid|Embpar|Minasmaquina|Rodobens|Wlm Ind Com/gm", text):
|
34 |
+
return "Industrial Goods"
|
35 |
+
elif re.search(r"/Algar Telec|Brisanet|Desktop|Oi|Telebras|Telef Brasil|Tim|Unifique|Cinesystem|Eletromidia|Vivo|Claro|Tim/gm", text):
|
36 |
+
return "Communications"
|
37 |
+
elif re.search(r"/Alphaville|Const A Lind|Cr2Cury|Cyrela Realt|DirecionalEvenEztecGafisaHelborInter SaJhsf PartJoao FortesKallas|Lavvi|Melnick|Mitre Realty|Moura Dubeux|MrvPdg RealtPlanoeplano|Rni|Rossi ResidTecnisaTegra Incorp|Tenda|TrisulViverCedroCoteminasDohlerInd Cataguas|KarstenPettenatiSantanenseSpringsTekaTex RenauxTrack Field|AlpargatasCambuciGrendeneVulcabrasMundialTechnosVivara|WhirlpoolUnicasa|Hercules|Iochp-maxion|Metal Leve|Plascar Part|Hoteis Othon|Bk Brasil|Imc|Bic MonarkEstrelaSpturisTime For Fun|Cvc Brasil|Smart Fit|Anima|BahemaCogna On|Cruzeiro Edu|Ser Educa|Yduqs Part|LocalizaLocamerica|Maestroloc|Movida|UnidasVamos|Dotz Sa|Arezzo CoCea Modas|GrazziotinGrupo Soma|GuararapesLe Lis Blanc|Lojas Marisa|Lojas Renner|Allied|Magaz LuizaVia|Americanas|Espacolaser|Grupo Sbf|Le Biscuit|Petz|Quero-quero|Saraiva Livr|Saraiva|Burguer King/gm", text):
|
38 |
+
return "Cyclic Consumption"
|
39 |
+
elif re.search(r"/3tentos|Agribrasil|Agrogalaxy|Aliperti|Boa Safra|Brasilagro|Pomifrutas|Raizen|Slc Agricola|Terrasantapa|Jallesmachad|Raizen Energ|Sao Martinho|Carnes E Derivados|Brf Sa|Excelsior|Jbs|Marfrig|Minerva|Minupar|Camil|J.macedo|Josapar|M.diasbranco|Oderich|Ambev|Grupo Natura|Bombril|Assai|Carrefour Br|Grupo Mateus|P.acucar-cbd|Natura|Pão de Açúcar|Raizen|JBS|Carrefour/gm", text):
|
40 |
+
return "Non-cyclical Consumption"
|
41 |
+
elif re.search(r"/Abc Brasil|Alfa Holding|Alfa Invest|Amazonia|Banco Bmg|Banco Inter|Banco Pan|Banese|Banestes|Banpara|Banrisul|Br Partners|Bradesco|Brasil|Brb Banco|Btgp Banco|Itausa|Itauunibanco|Merc Brasil|Merc Invest|Modalmais|Nord Brasil|Nu-nubank|Parana|Pine|Santander Br|Alfa Financ|Finansinos|Merc Financ|Bradesco Lsg|Dibens Lsg|Brazil Realt|Brazilian Sc|Brpr 56 Sec|Cibrasec|Eco Sec Agro|Gaia Agro|Gaia Securit|Octante Sec|Pdg Securit|Polo Cap Sec|Rbcapitalres|Truesec|Vertciasec|Wtorre Pic|Bndespar|Brazilian Fr|G2d Invest|Gp Invest|Ppla|B3|Boa Vista|Cielo|Clearsale|Csu Cardsyst|Getnet Br|Stone Co|Xp Inc|Alfa Consorc|Bbseguridade|Caixa Seguri|Porto Seguro|Seg Al Bahia|Sul America|Irbbrasil Re|Alper|Wiz|Alianscsonae|Br Malls Par|Br Propert|Cor Ribeiro|Cyre Com-ccp|Generalshopp|Habitasul|Hbr Realty|Igb|Iguatemi|Log Com Prop|Menezes Cort|Multiplan|Sao Carlos|Syn Prop Tec|Lopes Brasil|Nexpe|Mont Aranha|Par Al Bahia|Simpar|Cepac - Ctba|Cepac - Mcrj|Cepac - Pmsp|Inter|Pan|Banco do Brasil|BTG|Itaú|Nubank|Santander|Alfa|Merc|BNDES|/gm", text):
|
42 |
+
return "Financial"
|
43 |
+
elif re.search(r"/Aura 360|Bradespar|CBA|Csnmineracao|Litel|Litela|Mmx Miner|Vale|Ferbasa|Gerdau|Gerdau Met|Sid Nacional|Usiminas|Mangels Indl|Panatlantica|Tekno|Paranapanema|Braskem|Dexxos Par|Fer Heringer|Nutriplant|Vittia|Cristal|Unipar|Dexco|Eucatex|Klabin|Melhor Sp|Suzano Hold|Suzano|Irani|Metal Iguacu|Sansuy/gm", text):
|
44 |
+
return "Basic Materials"
|
45 |
+
#elif re.search(r"/524 Particip|Atompar|B Tech Eqi|Betapart |Cabinda Part|Caconde Part|Cemepe |Cims |Gama Part |Invest Bemge|Polpar |Prompt Part |Sudeste|Sul 116 Part|Ybyra/gm", text):
|
46 |
+
#return "Others"
|
47 |
+
elif re.search(r"/3r Petroleum|Cosan|Dommo|Enauta Part|Pet Manguinh|Petrobras|Petrorecsa|Petrorio|Ultrapar|Vibra|Lupatech|Oceanpact|Osx Brasil/gm", text):
|
48 |
+
return "Oil, Gas and Biofuels"
|
49 |
+
elif re.search(r"/Intelbras|Multilaser|Positivo Tec|Bemobi Tech|Brq|Enjoei|Getninjas|Infracomm|Locaweb|Meliuz|Mobly|Neogrid|Padtec|Quality Soft|Sinqia|Tc|Totvs |Wdc Networks|Westwing/gm", text):
|
50 |
+
return "Information Technology"
|
51 |
+
elif re.search(r"/Aes Brasil|Aes Sul|Aesoperacoes|Afluente T|Alupar|Ampla Energ|Auren|Cachoeira|Ceb|Ceee-d|Ceee-t|Celesc|Celgpar|Celpe|Cemig|Cemig Dist|Cemig Gt|Coelba|Coelce|Comerc Par|Copel|Cosern|Cpfl Energia|Cpfl Geracao|Cpfl Piratin|Cpfl Renovav|Ebe|Elektro|Eletrobras|Eletropar|Emae|Energias Br|Energisa|Energisa Mt|Enersul|Eneva|Engie Brasil|Eqtl Para|Eqtlmaranhao|Equatorial|Escelsa|Fgenergia|Ger Paranap|Itapebi|Light|Light S/a|Neoenergia|Omegaenergia|Paul F Luz|Proman|Rede Energia|Renova|Statkraft|Sto Antonio|Taesa|Term. Pe Iii|Termope|Tran Paulist|Uptick|Ambipar|Casan|Copasa|Igua Sa|Orizon|Sabesp|Sanepar|Sanesalto|Ceg|Comgas|Compass|AES|Cemig|CEMIG/gm", text):
|
52 |
+
return "Public utility"
|
53 |
+
else:
|
54 |
+
labels = [
|
55 |
+
"Industrial Goods",
|
56 |
+
"Communications",
|
57 |
+
"Cyclic Consumption",
|
58 |
+
"Non-cyclical Consumption",
|
59 |
+
"Financial",
|
60 |
+
"Basic Materials",
|
61 |
+
#"Others",
|
62 |
+
"Oil, Gas and Biofuels",
|
63 |
+
"Health",
|
64 |
+
#"Initial Sector",
|
65 |
+
"Information Technology",
|
66 |
+
"Public utility"
|
67 |
+
]
|
68 |
|
69 |
+
template = "The economic sector of this set of words is {}."
|
70 |
|
71 |
+
results = text_classifier(text, labels, hypothesis_template=template)
|
72 |
|
73 |
+
index = results["scores"].index(max(results["scores"]))
|
74 |
|
75 |
+
return str(results["labels"][index])
|
76 |
+
|
77 |
+
sid_obj = SentimentIntensityAnalyzer()
|
78 |
+
classifier = pipeline("zero-shot-classification", model="joeddav/xlm-roberta-large-xnli")
|
79 |
|
80 |
header = st.container()
|
81 |
model = st.container()
|
82 |
+
dataset = st.container()
|
83 |
|
84 |
with st.sidebar:
|
85 |
st.markdown("# Lorem Ipsum\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sapien tortor, suscipit quis ornare ut, laoreet vitae nisi. Mauris quis consectetur risus, non blandit mauris. Sed ut odio tempor, ullamcorper leo eu, mollis eros. Curabitur pretium sollicitudin sapien, vel mattis augue convallis quis. Suspendisse eleifend turpis non nunc gravida, aliquet hendrerit orci viverra. Sed aliquet, nunc eu posuere tempor, libero ex dignissim velit, ut ultricies erat felis at urna. Proin metus augue, commodo in faucibus sed, aliquet ac eros. Nullam turpis leo, dictum eu tellus a, aliquam egestas velit. Suspendisse cursus augue a sem dapibus, eu faucibus nisl ultrices. Cras tortor ipsum, luctus vitae tincidunt id, dapibus id justo. Sed mi nunc, tempor eu iaculis in, tristique cursus massa. Integer metus felis, pulvinar ut aliquam ut, consectetur in nulla.")
|
86 |
|
87 |
with header:
|
88 |
st.title("IC 2022 Classificação de Dados Financeiros")
|
89 |
+
st.write("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sapien tortor, suscipit quis ornare ut, laoreet vitae nisi. Mauris quis consectetur risus, non blandit mauris. Sed ut odio tempor, ullamcorper leo eu, mollis eros.")
|
90 |
|
91 |
with model:
|
92 |
st.header("Modelo para Tradução e Classificação!")
|
93 |
+
text = st.text_area("Coloque seu texto sobre mercado financeiro em português!")
|
94 |
+
|
95 |
+
if text:
|
96 |
+
text_en = translate_text(text)
|
97 |
+
st.write("Translation: {}".format(text_en))
|
98 |
+
sentiment = sentiment_classification(text_en, sid_obj)
|
99 |
+
st.write("Sentiment: {} - {}".format(sentiment[0], sentiment[1]))
|
100 |
+
theme = theme_classification(text_en, classifier)
|
101 |
+
st.write("Theme: {}".format(theme))
|
102 |
|
103 |
+
with dataset:
|
104 |
+
st.header("Dados utilizados no projeto!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|