mlbict / app.py
zangkawai's picture
Update app.py
4562cac verified
import streamlit as st
import requests
import streamlit.components.v1 as components
import time
import pandas as pd
from datetime import datetime
# Hàm để gọi API và hiển thị kết quả
def get(url):
response = requests.get(url)
return response.json()
def extract_data(data):
extracted_data = []
for time, details in data.items():
signal = details.get("signal")
extracted_data.append({"time": time, "signal": signal})
return extracted_data
# Tạo nút "Get Predict Signal"
signal_real = "Sell"
time_real = "None"
# Initialize state
if 'signal' not in st.session_state:
st.session_state.signal = None
st.session_state.update_time = None
# Create a button
if st.button('Show Bitcoin Signal'):
url = st.secrets["url_api"]
data = get(url)
extracted_data = extract_data(data)
for entry in extracted_data:
time_real = entry['time']
signal_real = entry['signal']
signal, update_time = signal_real, time_real
st.session_state.signal = signal
st.session_state.update_time = update_time
# Define colors based on the signal
if st.session_state.signal == 'Buy':
color = '#4CAF50'
elif st.session_state.signal == 'Sell':
color = '#FF4C4C'
else:
color = '#888888' # Default color (gray) before the button is clicked
# Display the signal and update time in a styled box
st.markdown(
f"""
<div style="border: 2px solid {color}; border-radius: 10px; padding: 20px; margin-top: 20px;">
<h2 style="color: {color};">Bitcoin Signal: {st.session_state.signal if st.session_state.signal else 'N/A'}</h2>
<p style="font-size: 16px; color: #777;">Time Update: {st.session_state.update_time if st.session_state.update_time else 'N/A'}</p>
</div>
""",
unsafe_allow_html=True
)