Spaces:
Runtime error
Runtime error
Commit
·
323db28
1
Parent(s):
e5c55f8
Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,53 @@ def sentiment_finbert(text, pipeline):
|
|
40 |
return result["label"].upper()
|
41 |
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
m2m100 = pipeline("translation_pt_to_en", src_lang="pt", tgt_lang="en", model="facebook/m2m100_418M")
|
44 |
opus = pipeline("translation_pt_to_en", src_lang="pt", tgt_lang="en", model="Helsinki-NLP/opus-mt-mul-en")
|
45 |
finbert = pipeline("sentiment-analysis",model="ProsusAI/finbert", tokenizer="ProsusAI/finbert")
|
@@ -53,8 +100,8 @@ url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sh
|
|
53 |
df = pd.read_csv(url)
|
54 |
|
55 |
header = st.container()
|
56 |
-
model_1, model_2 = st.columns(2)
|
57 |
model = st.container()
|
|
|
58 |
dataset = st.container()
|
59 |
analysis = st.container()
|
60 |
|
@@ -65,34 +112,40 @@ with header:
|
|
65 |
st.title("IC 2022 Classificação de Dados Financeiros")
|
66 |
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.")
|
67 |
|
68 |
-
with
|
69 |
-
st.header("Modelo para Tradução e Classificação!")
|
70 |
-
translator = st.selectbox(
|
71 |
-
'Qual modelo você deseja usar para tradução?', ('TextBlob', 'M2M100', 'OPUS'))
|
72 |
-
sentimentor = st.selectbox(
|
73 |
-
'Qual modelo você deseja usar para a análise de sentimentos?', ('Vader', 'FinBERT'))
|
74 |
-
|
75 |
-
text = st.text_input(label="Coloque seu texto sobre mercado financeiro em português!", value=r"As ações da Raia Drogasil subiram em 98% desde o último bimestre, segundo as avaliações da revista!")
|
76 |
-
|
77 |
-
with model_2:
|
78 |
-
if text:
|
79 |
-
if translator == "TextBlob":
|
80 |
-
text_en = translate_text_blob(text)
|
81 |
-
elif translator == "M2M100":
|
82 |
-
text_en = translate_text_transformer(text, m2m100)
|
83 |
-
elif translator == "OPUS":
|
84 |
-
text_en = translate_text_transformer(text, opus)
|
85 |
-
|
86 |
-
if sentimentor == "Vader":
|
87 |
-
sentiment = sentiment_vader(text_en, sid_obj)
|
88 |
-
elif sentimentor == "FinBERT":
|
89 |
-
sentiment = sentiment_finbert(text_en, finbert_pipeline)
|
90 |
|
91 |
-
|
92 |
-
st.text_area(label="", value="Sentiment: " + sentiment)
|
93 |
|
94 |
-
|
95 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
'''
|
98 |
with model:
|
@@ -123,4 +176,4 @@ with dataset:
|
|
123 |
st.write("\t*- Texts:* Coluna que mostra os textos financeiros")
|
124 |
|
125 |
with analysis:
|
126 |
-
st.header("Visualização dos dados utilizados")
|
|
|
40 |
return result["label"].upper()
|
41 |
|
42 |
|
43 |
+
def theme_classification(text, text_classifier):
|
44 |
+
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):
|
45 |
+
return "Health"
|
46 |
+
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):
|
47 |
+
return "Industrial Goods"
|
48 |
+
elif re.search(r"/Algar Telec|Brisanet|Desktop|Oi|Telebras|Telef Brasil|Tim|Unifique|Cinesystem|Eletromidia|Vivo|Claro|Tim/gm", text):
|
49 |
+
return "Communications"
|
50 |
+
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):
|
51 |
+
return "Cyclic Consumption"
|
52 |
+
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):
|
53 |
+
return "Non-cyclical Consumption"
|
54 |
+
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):
|
55 |
+
return "Financial"
|
56 |
+
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):
|
57 |
+
return "Basic Materials"
|
58 |
+
#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):
|
59 |
+
#return "Others"
|
60 |
+
elif re.search(r"/3r Petroleum|Cosan|Dommo|Enauta Part|Pet Manguinh|Petrobras|Petrorecsa|Petrorio|Ultrapar|Vibra|Lupatech|Oceanpact|Osx Brasil/gm", text):
|
61 |
+
return "Oil, Gas and Biofuels"
|
62 |
+
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):
|
63 |
+
return "Information Technology"
|
64 |
+
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):
|
65 |
+
return "Public utility"
|
66 |
+
else:
|
67 |
+
labels = [
|
68 |
+
"Industrial Goods",
|
69 |
+
"Communications",
|
70 |
+
"Cyclic Consumption",
|
71 |
+
"Non-cyclical Consumption",
|
72 |
+
"Financial",
|
73 |
+
"Basic Materials",
|
74 |
+
#"Others",
|
75 |
+
"Oil, Gas and Biofuels",
|
76 |
+
"Health",
|
77 |
+
#"Initial Sector",
|
78 |
+
"Information Technology",
|
79 |
+
"Public utility"
|
80 |
+
]
|
81 |
+
|
82 |
+
template = "The economic sector of this set of words is {}."
|
83 |
+
|
84 |
+
results = text_classifier(text, labels, hypothesis_template=template)
|
85 |
+
|
86 |
+
index = results["scores"].index(max(results["scores"]))
|
87 |
+
|
88 |
+
return str(results["labels"][index])
|
89 |
+
|
90 |
m2m100 = pipeline("translation_pt_to_en", src_lang="pt", tgt_lang="en", model="facebook/m2m100_418M")
|
91 |
opus = pipeline("translation_pt_to_en", src_lang="pt", tgt_lang="en", model="Helsinki-NLP/opus-mt-mul-en")
|
92 |
finbert = pipeline("sentiment-analysis",model="ProsusAI/finbert", tokenizer="ProsusAI/finbert")
|
|
|
100 |
df = pd.read_csv(url)
|
101 |
|
102 |
header = st.container()
|
|
|
103 |
model = st.container()
|
104 |
+
model_1, model_2 = st.columns(2)
|
105 |
dataset = st.container()
|
106 |
analysis = st.container()
|
107 |
|
|
|
112 |
st.title("IC 2022 Classificação de Dados Financeiros")
|
113 |
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.")
|
114 |
|
115 |
+
with model:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
st.header("Modelo para Tradução e Classificação!")
|
|
|
118 |
|
119 |
+
with model_1:
|
120 |
+
translator = st.selectbox(
|
121 |
+
'Qual modelo você deseja usar para tradução?', ('TextBlob', 'M2M100', 'OPUS'))
|
122 |
+
sentimentor = st.selectbox(
|
123 |
+
'Qual modelo você deseja usar para a análise de sentimentos?', ('Vader', 'FinBERT'))
|
124 |
+
|
125 |
+
text = st.text_input(label="Coloque seu texto sobre mercado financeiro em português!", value=r"As ações da Raia Drogasil subiram em 98% desde o último bimestre, segundo as avaliações da revista!")
|
126 |
+
|
127 |
+
submit = st.button('Gerar análises!')
|
128 |
+
|
129 |
+
with model_2:
|
130 |
+
if submit:
|
131 |
+
if translator == "TextBlob":
|
132 |
+
text_en = translate_text_blob(text)
|
133 |
+
elif translator == "M2M100":
|
134 |
+
text_en = translate_text_transformer(text, m2m100)
|
135 |
+
elif translator == "OPUS":
|
136 |
+
text_en = translate_text_transformer(text, opus)
|
137 |
+
|
138 |
+
if sentimentor == "Vader":
|
139 |
+
sentiment = sentiment_vader(text_en, sid_obj)
|
140 |
+
elif sentimentor == "FinBERT":
|
141 |
+
sentiment = sentiment_finbert(text_en, finbert)
|
142 |
+
|
143 |
+
theme = theme_classification(text_en, classifier)
|
144 |
+
|
145 |
+
st.write(text_en)
|
146 |
+
st.write("\n")
|
147 |
+
st.write(sentiment)
|
148 |
+
st.write("\n")
|
149 |
|
150 |
'''
|
151 |
with model:
|
|
|
176 |
st.write("\t*- Texts:* Coluna que mostra os textos financeiros")
|
177 |
|
178 |
with analysis:
|
179 |
+
st.header("Visualização dos dados utilizados")
|