missbaj commited on
Commit
7d92aef
·
verified ·
1 Parent(s): 6daa098
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -13,7 +13,7 @@ def fetch_historical_data(coin_id, from_timestamp, to_timestamp):
13
  prices = data.get('prices', [])
14
  return prices
15
  except requests.RequestException as e:
16
- return str(e)
17
 
18
  # Function to fetch current prices from CoinGecko
19
  def fetch_current_price(coin_id):
@@ -24,7 +24,7 @@ def fetch_current_price(coin_id):
24
  data = response.json()
25
  return data[coin_id]['usd']
26
  except requests.RequestException as e:
27
- return str(e)
28
 
29
  # Function to convert dates to timestamps
30
  def date_to_timestamp(date_str):
@@ -38,7 +38,9 @@ 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 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')
@@ -73,7 +75,7 @@ def get_real_time_trade_data():
73
  latest_price = data['prices'][-1][1] if data['prices'] else "N/A"
74
  return f"Latest trading data for Bitcoin is: ${latest_price}"
75
  except requests.RequestException as e:
76
- return str(e)
77
 
78
  # Function to analyze Bitcoin based on the prompt
79
  def analyze_btc(prompt):
 
13
  prices = data.get('prices', [])
14
  return prices
15
  except requests.RequestException as e:
16
+ return f"Error fetching historical data: {e}"
17
 
18
  # Function to fetch current prices from CoinGecko
19
  def fetch_current_price(coin_id):
 
24
  data = response.json()
25
  return data[coin_id]['usd']
26
  except requests.RequestException as e:
27
+ return f"Error fetching current price: {e}"
28
 
29
  # Function to convert dates to timestamps
30
  def date_to_timestamp(date_str):
 
38
  prices = fetch_historical_data(coin_name, from_timestamp, to_timestamp)
39
 
40
  if isinstance(prices, str): # In case of error
41
+ fig = go.Figure()
42
+ fig.update_layout(title=prices)
43
+ return fig
44
 
45
  df = pd.DataFrame(prices, columns=['timestamp', 'price'])
46
  df['date'] = pd.to_datetime(df['timestamp'], unit='ms')
 
75
  latest_price = data['prices'][-1][1] if data['prices'] else "N/A"
76
  return f"Latest trading data for Bitcoin is: ${latest_price}"
77
  except requests.RequestException as e:
78
+ return f"Error fetching real-time trade data: {e}"
79
 
80
  # Function to analyze Bitcoin based on the prompt
81
  def analyze_btc(prompt):