Spaces:
Sleeping
Sleeping
File size: 1,356 Bytes
1f53c35 4ca1459 32dbc75 8969074 c4253c7 1f53c35 7fcc38d 8969074 32dbc75 1f53c35 c4253c7 32dbc75 f26f395 32dbc75 4ca1459 1f53c35 a3d4593 32dbc75 1f53c35 8969074 1f53c35 f26f395 a3d4593 f26f395 4ca1459 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import requests
import gradio as gr
def get_crypto_compare_price():
"""Fetch the Bitcoin price from CryptoCompare."""
try:
# Replace 'YOUR_API_KEY' with your actual CryptoCompare API key
api_key = 'c1e07b0b9a72b6f5ea096763a17a2a1eec7a925a10faadd615b2d152f208a98d'
headers = {
'Authorization': f'Apikey {api_key}'
}
response = requests.get(
"https://min-api.cryptocompare.com/data/price",
params={"fsym": "BTC", "tsyms": "USD"},
headers=headers
)
response.raise_for_status() # Raise an HTTPError for bad responses
data = response.json()
return f"BTC Price (CryptoCompare): ${data['USD']:.2f}"
except requests.exceptions.RequestException as e:
return f"Error fetching CryptoCompare data: {str(e)}"
def analyze_btc(prompt):
"""Analyze the prompt and provide information on Bitcoin price."""
if "price" in prompt.lower():
return get_crypto_compare_price()
return "Try asking about the BTC price."
# Set up the Gradio interface
interface = gr.Interface(
fn=analyze_btc,
inputs="text",
outputs="text",
title="Bitcoin Price Analyzer",
description="Ask about the current Bitcoin price. For example: 'What's the price of Bitcoin?'"
)
# Launch the Gradio app
interface.launch()
|