File size: 1,223 Bytes
a1f7b8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 56 57 58 59 60 61 62 63 |
import yfinance as yf
from transformers import pipeline
from collections import Counter
import gradio as gr
def search(symbol):
bot=pipeline('sentiment-analysis')
ticker=yf.Ticker(symbol)
pos=0
neg=0
neu=0
news=ticker.news
for item in news[:100]:
content=item['content']['title']
result=bot(content)
sentiment=result[0]['label']
if sentiment=='POSITIVE':
pos+=1
elif sentiment=='NEGATIVE':
neg+=1
else:
neu+=1
print('Positive news: '+str(pos))
print('Negative news: '+str(neg))
print('Neutral news: '+str(neu))
if pos>neg and pos>neu:
overall='BULLISH'
elif neg>pos and neg>neu:
overall='BEARISH'
else:
overall='NEUTRAL'
return 'Out of 10 results'+'\nPositive news: '+str(pos)+'\nNegative news: '+str(neg)+'\nNeutral news: '+str(neu)+'\n'+'Overall Sentiment: '+overall
with gr.Blocks(theme=gr.themes.Soft()) as window:
gr.Markdown('## Market Sentiment Analysis')
inp=gr.Textbox(label='Enter Ticker correctly',placeholder='For example:AAPL')
btn=gr.Button('Search')
display=gr.TextArea(label=' ')
btn.click(fn=search,inputs=inp,outputs=display)
window.launch()
|