Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,8 @@ import pandas as pd
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
import matplotlib.pyplot as plt
|
5 |
-
import
|
|
|
6 |
from transformers import pipeline
|
7 |
|
8 |
# Initialize Summarizer
|
@@ -30,16 +31,17 @@ def discounted_cash_flow(fcf, growth_rate, discount_rate, terminal_growth_rate,
|
|
30 |
return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value
|
31 |
|
32 |
def get_company_fcf(symbol):
|
33 |
-
|
|
|
34 |
try:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
except Exception as e:
|
44 |
print(f"DEBUG: Error fetching FCF for {symbol}: {e}")
|
45 |
return None
|
@@ -98,8 +100,8 @@ iface = gr.Interface(
|
|
98 |
["AAPL", 0.06, 0.08, 0.025, 5]
|
99 |
],
|
100 |
title="AI-Powered DCF Valuation Calculator",
|
101 |
-
description="Enter a stock symbol and your assumptions. The app pulls live data, runs a DCF, and generates a research summary."
|
102 |
)
|
103 |
|
104 |
if __name__ == "__main__":
|
105 |
-
iface.launch()
|
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
import matplotlib.pyplot as plt
|
5 |
+
import requests
|
6 |
+
import os
|
7 |
from transformers import pipeline
|
8 |
|
9 |
# Initialize Summarizer
|
|
|
31 |
return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value
|
32 |
|
33 |
def get_company_fcf(symbol):
|
34 |
+
api_key = os.getenv("POLYGON_API_KEY")
|
35 |
+
url = f"https://api.polygon.io/vX/reference/financials?ticker={symbol}&apiKey={api_key}"
|
36 |
try:
|
37 |
+
response = requests.get(url)
|
38 |
+
response.raise_for_status()
|
39 |
+
data = response.json()
|
40 |
+
|
41 |
+
# Navigate the JSON to find Free Cash Flow
|
42 |
+
fcf = data['results'][0]['financials']['cash_flow_statement']['free_cash_flow']['value']
|
43 |
+
return float(fcf)
|
44 |
+
|
45 |
except Exception as e:
|
46 |
print(f"DEBUG: Error fetching FCF for {symbol}: {e}")
|
47 |
return None
|
|
|
100 |
["AAPL", 0.06, 0.08, 0.025, 5]
|
101 |
],
|
102 |
title="AI-Powered DCF Valuation Calculator",
|
103 |
+
description="Enter a stock symbol and your assumptions. The app pulls live data from Polygon.io, runs a DCF, and generates a research summary."
|
104 |
)
|
105 |
|
106 |
if __name__ == "__main__":
|
107 |
+
iface.launch()
|