Spaces:
Sleeping
Sleeping
| 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 | |