File size: 1,142 Bytes
743b3f2
 
1325fc5
72b3c77
743b3f2
72b3c77
 
 
 
 
 
 
 
743b3f2
72b3c77
 
 
 
 
 
 
 
 
 
743b3f2
72b3c77
743b3f2
 
72b3c77
743b3f2
 
72b3c77
 
 
 
 
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
import streamlit as st
import pandas as pd
import requests
import io  # Import io for StringIO

# Hugging Face dataset URL
HF_USERNAME = "abolfazle80"
REPO_NAME = "crypto_data"
CSV_FILENAME = "USDT.csv"
HF_CSV_URL = f"https://huggingface.co/datasets/{HF_USERNAME}/{REPO_NAME}/resolve/main/{CSV_FILENAME}"

# Function to fetch latest data
def fetch_latest_data():
    try:
        response = requests.get(HF_CSV_URL)
        response.raise_for_status()  # Raise an error if request fails

        # Use io.StringIO instead of pandas.compat.StringIO
        csv_data = io.StringIO(response.text)  
        df = pd.read_csv(csv_data)
        
        return df.tail()  # Show last few rows
    except requests.exceptions.RequestException as e:
        return f"Failed to fetch data: {e}"
    except Exception as e:
        return f"Error processing data: {e}"

# Streamlit UI
st.title("πŸ“Š View Latest Crypto Data")

if st.button("Show Latest Data"):
    latest_data = fetch_latest_data()
    if isinstance(latest_data, str):  # Check if error occurred
        st.error(latest_data)
    else:
        st.write(latest_data)  # Display DataFrame