Spaces:
Runtime error
Runtime error
Models modification
Browse files
app.py
CHANGED
@@ -7,12 +7,19 @@ from newspaper import Article
|
|
7 |
from newspaper import Config
|
8 |
from bs4 import BeautifulSoup
|
9 |
from datetime import datetime, timedelta
|
|
|
|
|
|
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
# Set up sentiment analysis and summarization pipelines
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# News API setup
|
18 |
def get_news_articles_info(ticker_name):
|
@@ -84,18 +91,19 @@ def index():
|
|
84 |
link = article['url']
|
85 |
content = article['text']
|
86 |
|
|
|
|
|
|
|
87 |
# Summarize article content
|
88 |
summary = summarization_pipeline(content, max_length=100, min_length=30, do_sample=False)[0]["summary_text"]
|
89 |
-
|
90 |
-
# Perform sentiment analysis on article content
|
91 |
-
sentiment = sentiment_analysis_pipeline(summary)[0]
|
92 |
|
93 |
news_data.append({
|
94 |
"title": title,
|
95 |
"link": link,
|
96 |
"sentiment": sentiment["label"],
|
97 |
"sentiment_score": round(sentiment["score"],3),
|
98 |
-
"summary": summary
|
|
|
99 |
})
|
100 |
|
101 |
print(link)
|
@@ -124,7 +132,7 @@ def index():
|
|
124 |
# convert the fig to HTML DIV element
|
125 |
graph_html = fig.to_html(full_html=False)
|
126 |
|
127 |
-
return render_template("index.html", news_data=news_data, candlestick_graph=graph_html)
|
128 |
|
129 |
return render_template("index.html")
|
130 |
|
|
|
7 |
from newspaper import Config
|
8 |
from bs4 import BeautifulSoup
|
9 |
from datetime import datetime, timedelta
|
10 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
11 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
12 |
+
|
13 |
|
14 |
app = Flask(__name__)
|
15 |
|
16 |
# Set up sentiment analysis and summarization pipelines
|
17 |
+
finbert = BertForSequenceClassification.from_pretrained('yiyanghkust/finbert-tone',num_labels=3)
|
18 |
+
sentiment_tokenizer = BertTokenizer.from_pretrained('yiyanghkust/finbert-tone')
|
19 |
+
summarization_model = BartForConditionalGeneration.from_pretrained("facebook/bart-large", forced_bos_token_id=0)
|
20 |
+
summarization_tokenizer = BartTokenizer.from_pretrained("facebook/bart-large")
|
21 |
+
sentiment_analysis_pipeline = pipeline("sentiment-analysis",model=finbert,tokenizer=sentiment_tokenizer,truncation = True,max_length = 512)
|
22 |
+
summarization_pipeline = pipeline("summarization",model=summarization_model,tokenizer=summarization_tokenizer,max_length = 512,truncation=True)
|
23 |
|
24 |
# News API setup
|
25 |
def get_news_articles_info(ticker_name):
|
|
|
91 |
link = article['url']
|
92 |
content = article['text']
|
93 |
|
94 |
+
# Perform sentiment analysis on article content
|
95 |
+
sentiment = sentiment_analysis_pipeline(content)[0]
|
96 |
+
|
97 |
# Summarize article content
|
98 |
summary = summarization_pipeline(content, max_length=100, min_length=30, do_sample=False)[0]["summary_text"]
|
|
|
|
|
|
|
99 |
|
100 |
news_data.append({
|
101 |
"title": title,
|
102 |
"link": link,
|
103 |
"sentiment": sentiment["label"],
|
104 |
"sentiment_score": round(sentiment["score"],3),
|
105 |
+
"summary": summary,
|
106 |
+
"Ticker": ticker
|
107 |
})
|
108 |
|
109 |
print(link)
|
|
|
132 |
# convert the fig to HTML DIV element
|
133 |
graph_html = fig.to_html(full_html=False)
|
134 |
|
135 |
+
return render_template("index.html", news_data=news_data, candlestick_graph=graph_html,ticker = ticker)
|
136 |
|
137 |
return render_template("index.html")
|
138 |
|