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()