Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,31 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
import requests
|
| 4 |
-
import yfinance as yf
|
| 5 |
-
import pandas_ta as ta
|
| 6 |
-
import cryptocompare
|
| 7 |
-
from tradingview_ta import TA_Handler, Interval
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
def get_coin_gecko_price():
|
|
|
|
| 11 |
try:
|
| 12 |
response = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd")
|
|
|
|
| 13 |
data = response.json()
|
| 14 |
return f"BTC Price (CoinGecko): ${data['bitcoin']['usd']:.2f}"
|
| 15 |
-
except
|
| 16 |
return f"Error fetching CoinGecko data: {str(e)}"
|
| 17 |
|
| 18 |
def analyze_btc(prompt):
|
|
|
|
| 19 |
if "price" in prompt.lower():
|
| 20 |
return get_coin_gecko_price()
|
| 21 |
return "Try asking about the BTC price."
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
| 25 |
interface.launch()
|
|
|
|
| 1 |
|
|
|
|
| 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
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=analyze_btc,
|
| 24 |
+
inputs="text",
|
| 25 |
+
outputs="text",
|
| 26 |
+
title="Bitcoin Price Analyzer",
|
| 27 |
+
description="Ask about the current Bitcoin price. For example: 'What's the price of Bitcoin?'"
|
| 28 |
+
)
|
| 29 |
|
| 30 |
+
# Launch the Gradio app
|
| 31 |
interface.launch()
|