CCockrum commited on
Commit
91d4d53
·
verified ·
1 Parent(s): eb0e697

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -152,10 +152,8 @@ def stock_research(symbol, assumed_eps=5.0, growth_rate=0.1, book_value=50000000
152
  dividends = get_dividends(symbol)
153
  dates, prices = get_historical_prices(symbol)
154
 
155
- if not info:
156
- return "⚠️ Error: Could not fetch company information. Please check your API Key or ticker.", None, None, None, None, None
157
- if not price:
158
- return "⚠️ Error: Could not fetch current stock price. Please check your API Key or ticker.", None, None, None, None, None
159
 
160
  ratios = calculate_ratios(info['Market Cap'], info['Total Revenue'], price, dividends['Dividend Amount'], assumed_eps, growth_rate, book_value)
161
  summary = generate_summary(info, ratios)
@@ -169,11 +167,21 @@ def stock_research(symbol, assumed_eps=5.0, growth_rate=0.1, book_value=50000000
169
  ax.legend()
170
  ax.grid(True)
171
 
172
- info_table = pd.DataFrame({"Metric": list(info.keys()), "Value": list(info.values())})
173
- ratios_table = pd.DataFrame({"Ratio": list(ratios.keys()), "Value": list(ratios.values())})
 
 
 
 
 
 
 
 
 
174
 
175
  return summary, info_table, ratios_table, sector_comp, fig
176
 
 
177
  def download_report(info_table, ratios_table, sector_comp, summary):
178
  with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode='w') as f:
179
  info_table.to_csv(f, index=False)
 
152
  dividends = get_dividends(symbol)
153
  dates, prices = get_historical_prices(symbol)
154
 
155
+ if not info or not price:
156
+ return "⚠️ Error: Could not fetch stock information. Please check your API Key or ticker.", None, None, None, None, None
 
 
157
 
158
  ratios = calculate_ratios(info['Market Cap'], info['Total Revenue'], price, dividends['Dividend Amount'], assumed_eps, growth_rate, book_value)
159
  summary = generate_summary(info, ratios)
 
167
  ax.legend()
168
  ax.grid(True)
169
 
170
+ # Format info_table
171
+ info_table = pd.DataFrame({
172
+ "Metric": list(info.keys()),
173
+ "Value": [f"${v:,.0f}" if isinstance(v, (int, float)) and abs(v) > 1000 else v for v in info.values()]
174
+ })
175
+
176
+ # ✅ Format ratios_table
177
+ ratios_table = pd.DataFrame({
178
+ "Ratio": list(ratios.keys()),
179
+ "Value": [f"{v:.3f}" if isinstance(v, float) else v for v in ratios.values()]
180
+ })
181
 
182
  return summary, info_table, ratios_table, sector_comp, fig
183
 
184
+
185
  def download_report(info_table, ratios_table, sector_comp, summary):
186
  with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode='w') as f:
187
  info_table.to_csv(f, index=False)