Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,36 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
-
import
|
| 5 |
-
# Hugging Face Dataset CSV URL
|
| 6 |
-
CSV_URL = "https://huggingface.co/datasets/abolfazle80/crypto_data/resolve/main/USDT.csv"
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
-
response = requests.get(
|
| 15 |
-
response.raise_for_status() # Raise error
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
-
|
| 20 |
-
return None
|
| 21 |
|
| 22 |
# Streamlit UI
|
| 23 |
-
st.title("
|
| 24 |
|
| 25 |
-
# Button to fetch and display the data
|
| 26 |
if st.button("Show Latest Data"):
|
| 27 |
-
|
| 28 |
-
if
|
| 29 |
-
st.
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
+
import io # Import io for StringIO
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Hugging Face dataset URL
|
| 7 |
+
HF_USERNAME = "abolfazle80"
|
| 8 |
+
REPO_NAME = "crypto_data"
|
| 9 |
+
CSV_FILENAME = "USDT.csv"
|
| 10 |
+
HF_CSV_URL = f"https://huggingface.co/datasets/{HF_USERNAME}/{REPO_NAME}/resolve/main/{CSV_FILENAME}"
|
| 11 |
+
|
| 12 |
+
# Function to fetch latest data
|
| 13 |
+
def fetch_latest_data():
|
| 14 |
try:
|
| 15 |
+
response = requests.get(HF_CSV_URL)
|
| 16 |
+
response.raise_for_status() # Raise an error if request fails
|
| 17 |
+
|
| 18 |
+
# Use io.StringIO instead of pandas.compat.StringIO
|
| 19 |
+
csv_data = io.StringIO(response.text)
|
| 20 |
+
df = pd.read_csv(csv_data)
|
| 21 |
+
|
| 22 |
+
return df.tail() # Show last few rows
|
| 23 |
+
except requests.exceptions.RequestException as e:
|
| 24 |
+
return f"Failed to fetch data: {e}"
|
| 25 |
except Exception as e:
|
| 26 |
+
return f"Error processing data: {e}"
|
|
|
|
| 27 |
|
| 28 |
# Streamlit UI
|
| 29 |
+
st.title("📊 View Latest Crypto Data")
|
| 30 |
|
|
|
|
| 31 |
if st.button("Show Latest Data"):
|
| 32 |
+
latest_data = fetch_latest_data()
|
| 33 |
+
if isinstance(latest_data, str): # Check if error occurred
|
| 34 |
+
st.error(latest_data)
|
| 35 |
+
else:
|
| 36 |
+
st.write(latest_data) # Display DataFrame
|