Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
CHANGED
|
@@ -6,14 +6,16 @@ import cryptocompare
|
|
| 6 |
from tradingview_ta import TA_Handler, Interval
|
| 7 |
import gradio as gr
|
| 8 |
|
|
|
|
| 9 |
def get_coin_gecko_price():
|
| 10 |
try:
|
| 11 |
response = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd")
|
| 12 |
data = response.json()
|
| 13 |
-
return data['bitcoin']['usd']
|
| 14 |
except Exception as e:
|
| 15 |
return f"Error fetching CoinGecko data: {str(e)}"
|
| 16 |
|
|
|
|
| 17 |
def get_yfinance_price():
|
| 18 |
try:
|
| 19 |
btc_data = yf.Ticker("BTC-USD")
|
|
@@ -60,17 +62,13 @@ def calculate_technical_indicators():
|
|
| 60 |
except Exception as e:
|
| 61 |
return f"Error calculating technical indicators: {str(e)}"
|
| 62 |
|
|
|
|
| 63 |
def analyze_btc(prompt):
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
price_cryptocompare = get_cryptocompare_price()
|
| 70 |
-
return (f"BTC Price (Yahoo Finance): ${price_yf:.2f}\n"
|
| 71 |
-
f"BTC Price (CoinGecko): ${price_cg:.2f}\n"
|
| 72 |
-
f"BTC Price (CryptoCompare): ${price_cryptocompare:.2f}")
|
| 73 |
-
|
| 74 |
elif "rsi" in prompt_lower or "macd" in prompt_lower or "moving average" in prompt_lower or "ma" in prompt_lower:
|
| 75 |
indicators = calculate_technical_indicators()
|
| 76 |
return (f"RSI: {indicators['RSI']:.2f}\n"
|
|
@@ -92,5 +90,7 @@ interface = gr.Interface(
|
|
| 92 |
description="Ask questions about BTC's real-time data (from CoinGecko, Yahoo Finance, CryptoCompare, TradingView)"
|
| 93 |
)
|
| 94 |
|
|
|
|
|
|
|
| 95 |
interface.launch()
|
| 96 |
|
|
|
|
| 6 |
from tradingview_ta import TA_Handler, Interval
|
| 7 |
import gradio as gr
|
| 8 |
|
| 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 Exception as e:
|
| 16 |
return f"Error fetching CoinGecko data: {str(e)}"
|
| 17 |
|
| 18 |
+
|
| 19 |
def get_yfinance_price():
|
| 20 |
try:
|
| 21 |
btc_data = yf.Ticker("BTC-USD")
|
|
|
|
| 62 |
except Exception as e:
|
| 63 |
return f"Error calculating technical indicators: {str(e)}"
|
| 64 |
|
| 65 |
+
|
| 66 |
def analyze_btc(prompt):
|
| 67 |
+
if "price" in prompt.lower():
|
| 68 |
+
return get_coin_gecko_price()
|
| 69 |
+
return "Try asking about the BTC price."
|
| 70 |
+
|
| 71 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
elif "rsi" in prompt_lower or "macd" in prompt_lower or "moving average" in prompt_lower or "ma" in prompt_lower:
|
| 73 |
indicators = calculate_technical_indicators()
|
| 74 |
return (f"RSI: {indicators['RSI']:.2f}\n"
|
|
|
|
| 90 |
description="Ask questions about BTC's real-time data (from CoinGecko, Yahoo Finance, CryptoCompare, TradingView)"
|
| 91 |
)
|
| 92 |
|
| 93 |
+
interface = gr.Interface(fn=analyze_btc, inputs="text", outputs="text")
|
| 94 |
+
|
| 95 |
interface.launch()
|
| 96 |
|