File size: 1,291 Bytes
06fc880
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import pandas as pd
import gradio as gr

# Assuming we have an API endpoint that provides the required data
API_ENDPOINT = "https://api.example.com/crypto/top-volume/12h"

def fetch_top_cryptos():
    # Placeholder for API call and data processing
    # In a real scenario, replace this with a call to the actual API
    response = requests.get(API_ENDPOINT)
    if response.status_code == 200:
        data = response.json()
        # Assuming the API returns data in a format that can be directly converted to a DataFrame
        df = pd.DataFrame(data)
        # Selecting and formatting the relevant columns
        df = df[['name', 'volume_invested']]
        return df
    else:
        return "Error fetching data"

# Gradio interface
iface = gr.Interface(
    fn=fetch_top_cryptos,
    inputs=None,
    outputs="dataframe",
    title="Top Cryptocurrencies by Volume",
    description="Shows the top cryptocurrencies by volume invested in the past 12 hours."
)

# The API key for deploying on Hugging Face Spaces
api_key = "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"

# Launch the app locally for testing
if __name__ == "__main__":
    iface.launch()

# To deploy on Hugging Face Spaces, use the `launch` method with `share=True` and the `api_key` parameter