sentivity commited on
Commit
5cd2ea8
·
verified ·
1 Parent(s): 1b63c04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -45,10 +45,14 @@ score_model.eval()
45
  def preprocess_text(text):
46
  text = text.lower()
47
  text = re.sub(r'http\S+', '', text)
 
 
 
48
  text = re.sub(r'[^a-zA-Z0-9\s.,!?]', '', text)
49
  text = re.sub(r'\s+', ' ', text).strip()
50
  return text
51
 
 
52
  # predicts sentiment
53
  def predict_sentiment(text):
54
  if not text:
@@ -171,8 +175,13 @@ def analyze_ticker(user_ticker: str):
171
  full_text = article_data["title"] + " " + article_data["text"]
172
  sentiment_score = predict_sentiment(full_text)
173
 
 
174
  snippet = article_data["text"][:500].replace("\n", " ").strip()
175
  blurb = f"{article_data['title']}\n\n{snippet}..."
 
 
 
 
176
 
177
  timestamp = datetime.datetime.utcnow()
178
  cache_entry = {
 
45
  def preprocess_text(text):
46
  text = text.lower()
47
  text = re.sub(r'http\S+', '', text)
48
+ text = re.sub(r'\d{1,2}:\d{2}', '', text)
49
+ text = re.sub(r'speaker\s+[a-z]', '', text)
50
+ text = re.sub(r'\b[a-z]{2,20}\s+howley\b', '', text)
51
  text = re.sub(r'[^a-zA-Z0-9\s.,!?]', '', text)
52
  text = re.sub(r'\s+', ' ', text).strip()
53
  return text
54
 
55
+
56
  # predicts sentiment
57
  def predict_sentiment(text):
58
  if not text:
 
175
  full_text = article_data["title"] + " " + article_data["text"]
176
  sentiment_score = predict_sentiment(full_text)
177
 
178
+ '''
179
  snippet = article_data["text"][:500].replace("\n", " ").strip()
180
  blurb = f"{article_data['title']}\n\n{snippet}..."
181
+ '''
182
+ cleaned_text = preprocess_text(article_data["text"])
183
+ short_blurb = cleaned_text[:300] + "..." if len(cleaned_text) > 300 else cleaned_text
184
+ blurb = f"{article_data['title']}\n\n{short_blurb}"
185
 
186
  timestamp = datetime.datetime.utcnow()
187
  cache_entry = {