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()