joaco7172 commited on
Commit
aada6a2
·
verified ·
1 Parent(s): 03b2f1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -138,28 +138,21 @@ def get_company_prompt(symbol):
138
 
139
 
140
  def get_prompt_by_row(symbol, row):
 
 
 
141
 
142
  start_date = row['Start Date'] if isinstance(row['Start Date'], str) else row['Start Date'].strftime('%Y-%m-%d')
143
  end_date = row['End Date'] if isinstance(row['End Date'], str) else row['End Date'].strftime('%Y-%m-%d')
144
- term = 'increased' if row['End Price'] > row['Start Price'] else 'decreased'
145
- head = "From {} to {}, {}'s stock price {} from {:.2f} to {:.2f}. Company news during this period are listed below:\n\n".format(
146
- start_date, end_date, symbol, term, row['Start Price'], row['End Price'])
147
 
148
  news = row["News"] if isinstance(row["News"], list) else json.loads(row["News"])
149
- news_formatted = ["[Headline]: {}\n[Summary]: {}\n".format(
150
- n['headline'], n['summary']) for n in news if n['date'][:8] <= end_date.replace('-', '') and \
151
- not n['summary'].startswith("Looking for stock market analysis and research with proves results?")]
152
-
153
  basics = json.loads(row['Basics'])
154
- if basics:
155
- basics = "Some recent basic financials of {}, reported at {}, are presented below:\n\n[Basic Financials]:\n\n".format(
156
- symbol, basics['period']) + "\n".join(f"{k}: {v}" for k, v in basics.items() if k != 'period')
157
- else:
158
- basics = "[Basic Financials]:\n\nNo basic financial reported."
159
 
160
  return head, news, basics
161
 
162
 
 
163
  def sample_news(news, k=5):
164
 
165
  return [news[i] for i in sorted(random.sample(range(len(news)), k))]
 
138
 
139
 
140
  def get_prompt_by_row(symbol, row):
141
+ end_price = float(row['End Price'])
142
+ start_price = float(row['Start Price'])
143
+ term = 'increased' if end_price > start_price else 'decreased'
144
 
145
  start_date = row['Start Date'] if isinstance(row['Start Date'], str) else row['Start Date'].strftime('%Y-%m-%d')
146
  end_date = row['End Date'] if isinstance(row['End Date'], str) else row['End Date'].strftime('%Y-%m-%d')
147
+ head = f"From {start_date} to {end_date}, {symbol}'s stock price {term} from {start_price:.2f} to {end_price:.2f}. Company news during this period are listed below:\n\n"
 
 
148
 
149
  news = row["News"] if isinstance(row["News"], list) else json.loads(row["News"])
 
 
 
 
150
  basics = json.loads(row['Basics'])
 
 
 
 
 
151
 
152
  return head, news, basics
153
 
154
 
155
+
156
  def sample_news(news, k=5):
157
 
158
  return [news[i] for i in sorted(random.sample(range(len(news)), k))]