john3huggingface commited on
Commit
5cb5b93
·
verified ·
1 Parent(s): 76c538d

feat: add app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Function to fetch comprehensive Bitcoin information from CoinGecko
5
+ def fetch_bitcoin_info():
6
+ # API endpoint for detailed Bitcoin information
7
+ endpoint = "https://api.coingecko.com/api/v3/coins/bitcoin"
8
+
9
+ # Send a GET request to the endpoint
10
+ response = requests.get(endpoint)
11
+
12
+ if response.status_code == 200:
13
+ data = response.json()
14
+
15
+ # Extract detailed information for Bitcoin
16
+ current_price = data["market_data"]["current_price"]["usd"]
17
+ market_cap = data["market_data"]["market_cap"]["usd"]
18
+ trading_volume_24h = data["market_data"]["total_volume"]["usd"]
19
+ rank = data["market_cap_rank"]
20
+ change_rate_24h = data["market_data"]["price_change_percentage_24h"]
21
+ all_time_high = data["market_data"]["ath"]["usd"]
22
+ number_of_markets = len(data["tickers"]) # Number of markets in which Bitcoin is listed
23
+ number_of_exchanges = len(set([ticker["market"]["name"] for ticker in data["tickers"]])) # Unique exchanges
24
+ total_supply = data["market_data"]["total_supply"]
25
+ circulating_supply = data["market_data"]["circulating_supply"]
26
+
27
+ # Create a formatted output
28
+ output = (
29
+ f"Bitcoin Price Information:\n"
30
+ f"Current Price: ${current_price:.2f}\n"
31
+ f"Market Cap: ${market_cap:.2f}\n"
32
+ f"24-Hour Trading Volume: ${trading_volume_24h:.2f}\n"
33
+ f"24-Hour Change Rate: {change_rate_24h:.2f}%\n"
34
+ f"All-Time High (ATH): ${all_time_high:.2f}\n"
35
+ f"Market Cap Rank: {rank}\n"
36
+ f"Number of Markets: {number_of_markets}\n"
37
+ f"Number of Exchanges: {number_of_exchanges}\n"
38
+ f"Total Supply: {total_supply:.2f}\n"
39
+ f"Circulating Supply: {circulating_supply:.2f}"
40
+ )
41
+ return output
42
+ else:
43
+ return "Failed to fetch Bitcoin information."
44
+
45
+ # Create the Gradio interface
46
+ with gr.Blocks() as demo:
47
+ # Create a textbox to display Bitcoin information
48
+ bitcoin_info_text = gr.Textbox(label="Bitcoin Information", interactive=False)
49
+
50
+ # Button to fetch Bitcoin information
51
+ fetch_button = gr.Button("Fetch Bitcoin Information")
52
+
53
+ # Connect the button click event to the function to fetch and display Bitcoin information
54
+ fetch_button.click(fetch_bitcoin_info, outputs=bitcoin_info_text)
55
+
56
+ # Launch the Gradio app
57
+ demo.launch(share=True)