missbaj commited on
Commit
6daa098
·
verified ·
1 Parent(s): 76b2ffc
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -8,7 +8,7 @@ def fetch_historical_data(coin_id, from_timestamp, to_timestamp):
8
  url = f"https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart/range?vs_currency=usd&from={from_timestamp}&to={to_timestamp}"
9
  try:
10
  response = requests.get(url)
11
- response.raise_for_status() # Will raise an HTTPError for bad responses
12
  data = response.json()
13
  prices = data.get('prices', [])
14
  return prices
@@ -38,7 +38,7 @@ def plot_historical_prices(coin_name, from_date, to_date):
38
  prices = fetch_historical_data(coin_name, from_timestamp, to_timestamp)
39
 
40
  if isinstance(prices, str): # In case of error
41
- return go.Figure()
42
 
43
  df = pd.DataFrame(prices, columns=['timestamp', 'price'])
44
  df['date'] = pd.to_datetime(df['timestamp'], unit='ms')
 
8
  url = f"https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart/range?vs_currency=usd&from={from_timestamp}&to={to_timestamp}"
9
  try:
10
  response = requests.get(url)
11
+ response.raise_for_status()
12
  data = response.json()
13
  prices = data.get('prices', [])
14
  return prices
 
38
  prices = fetch_historical_data(coin_name, from_timestamp, to_timestamp)
39
 
40
  if isinstance(prices, str): # In case of error
41
+ return gr.Plot(label="Error").plot(go.Figure().update_layout(title=prices))
42
 
43
  df = pd.DataFrame(prices, columns=['timestamp', 'price'])
44
  df['date'] = pd.to_datetime(df['timestamp'], unit='ms')