missbaj commited on
Commit
32dbc75
·
verified ·
1 Parent(s): f26f395
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -2,20 +2,29 @@
2
  import requests
3
  import gradio as gr
4
 
5
- def get_coin_gecko_price():
6
- """Fetch the Bitcoin price from CoinGecko."""
7
  try:
8
- response = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd")
 
 
 
 
 
 
 
 
 
9
  response.raise_for_status() # Raise an HTTPError for bad responses
10
  data = response.json()
11
- return f"BTC Price (CoinGecko): ${data['bitcoin']['usd']:.2f}"
12
  except requests.exceptions.RequestException as e:
13
- return f"Error fetching CoinGecko data: {str(e)}"
14
 
15
  def analyze_btc(prompt):
16
  """Analyze the prompt and provide information on Bitcoin price."""
17
  if "price" in prompt.lower():
18
- return get_coin_gecko_price()
19
  return "Try asking about the BTC price."
20
 
21
  # Set up the Gradio interface
 
2
  import requests
3
  import gradio as gr
4
 
5
+ def get_crypto_compare_price():
6
+ """Fetch the Bitcoin price from CryptoCompare."""
7
  try:
8
+ # Replace 'YOUR_API_KEY' with your actual CryptoCompare API key
9
+ api_key = 'YOUR_API_KEY'
10
+ headers = {
11
+ 'Authorization': f'Apikey {api_key}'
12
+ }
13
+ response = requests.get(
14
+ "https://min-api.cryptocompare.com/data/price",
15
+ params={"fsym": "BTC", "tsyms": "USD"},
16
+ headers=headers
17
+ )
18
  response.raise_for_status() # Raise an HTTPError for bad responses
19
  data = response.json()
20
+ return f"BTC Price (CryptoCompare): ${data['USD']:.2f}"
21
  except requests.exceptions.RequestException as e:
22
+ return f"Error fetching CryptoCompare data: {str(e)}"
23
 
24
  def analyze_btc(prompt):
25
  """Analyze the prompt and provide information on Bitcoin price."""
26
  if "price" in prompt.lower():
27
+ return get_crypto_compare_price()
28
  return "Try asking about the BTC price."
29
 
30
  # Set up the Gradio interface