Spaces:
Sleeping
Sleeping
new file
Browse files
app.py
CHANGED
|
@@ -25,74 +25,6 @@ You are a sentiment analysis expert. Answer all questions related to cryptocurre
|
|
| 25 |
|
| 26 |
initialize_session_state()
|
| 27 |
|
| 28 |
-
#st.image('el_pic.png')
|
| 29 |
-
|
| 30 |
-
sideb=st.sidebar
|
| 31 |
-
with st.sidebar:
|
| 32 |
-
prompt=st.text_input("Enter topic for sentiment analysis: ")
|
| 33 |
-
|
| 34 |
-
check1=sideb.button(f"analyze {prompt}")
|
| 35 |
-
|
| 36 |
-
if check1:
|
| 37 |
-
# Add user message to chat history
|
| 38 |
-
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 39 |
-
# Display user message in chat message container
|
| 40 |
-
with st.chat_message("user"):
|
| 41 |
-
st.markdown(prompt)
|
| 42 |
-
|
| 43 |
-
# ========================== Sentiment analysis
|
| 44 |
-
#Perform sentiment analysis on the cryptocurrency news & predict dominant sentiment along with plotting the sentiment breakdown chart
|
| 45 |
-
# Downloading from reddit
|
| 46 |
-
|
| 47 |
-
# Downloading from alpaca
|
| 48 |
-
if len(prompt.split(' '))<2:
|
| 49 |
-
print('here')
|
| 50 |
-
st.write('I am analyzing Google News ...')
|
| 51 |
-
news_articles = sentiment_analysis_util.fetch_news(str(prompt))
|
| 52 |
-
st.write('Now, I am analyzing Reddit ...')
|
| 53 |
-
reddit_news_articles=sentiment_analysis_util.fetch_reddit_news(prompt)
|
| 54 |
-
analysis_results = []
|
| 55 |
-
|
| 56 |
-
#Perform sentiment analysis for each product review
|
| 57 |
-
if len(prompt.split(' '))<2:
|
| 58 |
-
print('here')
|
| 59 |
-
for article in news_articles:
|
| 60 |
-
if prompt.lower()[0:6] in article['News_Article'].lower():
|
| 61 |
-
sentiment_analysis_result = sentiment_analysis_util.analyze_sentiment(article['News_Article'])
|
| 62 |
-
|
| 63 |
-
# Display sentiment analysis results
|
| 64 |
-
#print(f'News Article: {sentiment_analysis_result["News_Article"]} : Sentiment: {sentiment_analysis_result["Sentiment"]}', '\n')
|
| 65 |
-
|
| 66 |
-
result = {
|
| 67 |
-
'News_Article': sentiment_analysis_result["News_Article"],
|
| 68 |
-
'Sentiment': sentiment_analysis_result["Sentiment"][0]['label'],
|
| 69 |
-
'Index': sentiment_analysis_result["Sentiment"][0]['score'],
|
| 70 |
-
'URL': article['URL']
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
analysis_results.append(result)
|
| 74 |
-
|
| 75 |
-
articles_url=[]
|
| 76 |
-
for article in reddit_news_articles:
|
| 77 |
-
if prompt.lower()[0:6] in article.lower():
|
| 78 |
-
sentiment_analysis_result_reddit = sentiment_analysis_util.analyze_sentiment(article)
|
| 79 |
-
|
| 80 |
-
# Display sentiment analysis results
|
| 81 |
-
#print(f'News Article: {sentiment_analysis_result_reddit["News_Article"]} : Sentiment: {sentiment_analysis_result_reddit["Sentiment"]}', '\n')
|
| 82 |
-
|
| 83 |
-
result = {
|
| 84 |
-
'News_Article': sentiment_analysis_result_reddit["News_Article"],
|
| 85 |
-
'Index':np.round(sentiment_analysis_result_reddit["Sentiment"][0]['score'],2)
|
| 86 |
-
}
|
| 87 |
-
analysis_results.append(np.append(result,np.append(article.split('URL:')[-1:], ((article.split('Date: ')[-1:])[0][0:10]))))
|
| 88 |
-
#pd.DataFrame(analysis_results).to_csv('analysis_results.csv')
|
| 89 |
-
|
| 90 |
-
#Generate summarized message rationalize dominant sentiment
|
| 91 |
-
summary = sentiment_analysis_util.generate_summary_of_sentiment(analysis_results) #, dominant_sentiment)
|
| 92 |
-
st.chat_message("assistant").write((summary))
|
| 93 |
-
st.session_state.messages.append({"role": "assistant", "content": summary})
|
| 94 |
-
#answers=np.append(res["messages"][-1].content,summary)
|
| 95 |
-
|
| 96 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 97 |
|
| 98 |
if "openai_model" not in st.session_state:
|
|
|
|
| 25 |
|
| 26 |
initialize_session_state()
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 29 |
|
| 30 |
if "openai_model" not in st.session_state:
|