Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
CHANGED
|
@@ -2,20 +2,29 @@
|
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
"""Fetch the Bitcoin price from
|
| 7 |
try:
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
response.raise_for_status() # Raise an HTTPError for bad responses
|
| 10 |
data = response.json()
|
| 11 |
-
return f"BTC Price (
|
| 12 |
except requests.exceptions.RequestException as e:
|
| 13 |
-
return f"Error fetching
|
| 14 |
|
| 15 |
def analyze_btc(prompt):
|
| 16 |
"""Analyze the prompt and provide information on Bitcoin price."""
|
| 17 |
if "price" in prompt.lower():
|
| 18 |
-
return
|
| 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
|