ethanrom commited on
Commit
abbc24d
·
1 Parent(s): 3cf1036

Upload 7 files

Browse files
Files changed (7) hide show
  1. Hotpot.png +0 -0
  2. app.py +349 -0
  3. eth.PNG +0 -0
  4. get_new_coins.py +34 -0
  5. get_new_coins_auto.py +39 -0
  6. markup.py +27 -0
  7. requirements.txt +6 -0
Hotpot.png ADDED
app.py ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+ import numpy as np
5
+ import plotly.express as px
6
+ from sklearn.linear_model import LinearRegression
7
+ from sklearn.ensemble import RandomForestRegressor
8
+ from datetime import datetime, timedelta
9
+ from streamlit_option_menu import option_menu
10
+ from markup import real_estate_app, real_estate_app_hf
11
+ import feedparser
12
+
13
+ API_URL = "https://api.coingecko.com/api/v3"
14
+
15
+ PASSWORD = 'Ethan101'
16
+
17
+ def authenticate(password):
18
+ return password == PASSWORD
19
+
20
+ def get_ethereum_data():
21
+ response = requests.get(f"{API_URL}/coins/markets", params={"ids": "ethereum", "vs_currency": "usd"})
22
+ data = response.json()
23
+ return data
24
+
25
+ def format_price(price):
26
+ return "{:.10f}".format(price)
27
+
28
+ def get_new_tokens():
29
+ response = requests.get(f"{API_URL}/coins/ethereum/market_chart", params={"vs_currency": "usd", "days": 1})
30
+ data = response.json()
31
+
32
+ new_tokens = []
33
+ for token in data["market_caps"]:
34
+ timestamp, market_cap = token
35
+ if market_cap > 20000:
36
+ coin_token = data["prices"][data["market_caps"].index(token)][1]
37
+ coin_token_hex = float_to_hex(coin_token)
38
+ new_tokens.append((coin_token_hex, timestamp, market_cap))
39
+
40
+ # Sort the tokens based on the timestamp in descending order
41
+ new_tokens.sort(key=lambda x: x[1], reverse=True)
42
+
43
+ return new_tokens
44
+
45
+ def float_to_hex(f):
46
+ # Convert the float to its hexadecimal representation
47
+ _, hex_representation = f.hex().split('x')
48
+ return "0x" + hex_representation
49
+
50
+ def predict_price(df_price_history, days):
51
+ X = df_price_history.index.values.reshape(-1, 1)
52
+ y = df_price_history["price"].values
53
+ lr_model = LinearRegression()
54
+ lr_model.fit(X, y)
55
+ last_date = df_price_history.iloc[-1]["date"]
56
+ lr_future_dates = pd.date_range(last_date, periods=days+1)[1:]
57
+ lr_future_predictions = lr_model.predict(np.array(range(1, days+1)).reshape(-1, 1))
58
+ rf_model = RandomForestRegressor(n_estimators=100)
59
+ rf_model.fit(X, y)
60
+ rf_future_dates = pd.date_range(last_date, periods=days+1)[1:]
61
+ rf_future_predictions = rf_model.predict(np.array(range(1, days+1)).reshape(-1, 1))
62
+
63
+ return lr_future_dates, lr_future_predictions, rf_future_dates, rf_future_predictions
64
+
65
+ def tab1():
66
+ st.header("ethereum Cryptocurrency Predictions Demo")
67
+ col1, col2 = st.columns([1, 2])
68
+ with col1:
69
+ st.image("Hotpot.png", use_column_width=True)
70
+ with col2:
71
+ st.markdown(real_estate_app(), unsafe_allow_html=True)
72
+ st.markdown(real_estate_app_hf(),unsafe_allow_html=True)
73
+
74
+
75
+ github_link = '[<img src="https://badgen.net/badge/icon/github?icon=github&label">](https://github.com/ethanrom)'
76
+ #huggingface_link = '[<img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue">](https://huggingface.co/ethanrom)'
77
+
78
+ st.write(github_link + '&nbsp;&nbsp;&nbsp;', unsafe_allow_html=True)
79
+
80
+ def tab2():
81
+ ethereum_data = get_ethereum_data()
82
+ if ethereum_data:
83
+ ethereum_info = {
84
+ "Symbol": ethereum_data[0]["symbol"],
85
+ "Current Price": format_price(ethereum_data[0]["current_price"]),
86
+ "Market Cap": ethereum_data[0]["market_cap"],
87
+ "Total Volume": ethereum_data[0]["total_volume"],
88
+ "Circulating Supply": ethereum_data[0]["circulating_supply"],
89
+ }
90
+ df_ethereum = pd.DataFrame(ethereum_info, index=[0])
91
+
92
+ st.markdown("## Ethereum Information")
93
+ st.dataframe(df_ethereum)
94
+
95
+ # Visualize Market Cap and Total Volume
96
+ market_cap = ethereum_data[0]["market_cap"]
97
+ total_volume = ethereum_data[0]["total_volume"]
98
+ df_market_cap_volume = pd.DataFrame({"Metric": ["Market Cap", "Total Volume"],
99
+ "Value (USD)": [market_cap, total_volume]})
100
+ st.markdown("## Market Cap and Total Volume")
101
+ st.bar_chart(df_market_cap_volume, x="Metric", y="Value (USD)")
102
+ st.markdown(
103
+ """
104
+ The bar chart above shows the current market capitalization and total trading volume of Ethereum in USD.
105
+ """
106
+ )
107
+
108
+ circulating_supply = ethereum_data[0]["circulating_supply"]
109
+ max_supply = ethereum_data[0]["total_supply"]
110
+
111
+ st.markdown("## Supply Information")
112
+ st.write(f"**Circulating Supply:** {circulating_supply:.2f} Ethereum")
113
+ st.write(f"**Max Supply:** {max_supply:.2f} Ethereum")
114
+
115
+ # Additional Visualization: Pie Chart for Circulating vs. Max Supply
116
+ supply_data = pd.DataFrame({
117
+ "Supply": ["Circulating Supply", "Max Supply"],
118
+ "Amount (Ethereum)": [circulating_supply, max_supply]
119
+ })
120
+ fig = px.pie(supply_data, values="Amount (Ethereum)", names="Supply", title="Circulating vs. Max Supply")
121
+ st.markdown("## Circulating vs. Max Supply")
122
+ st.write(
123
+ """
124
+ The pie chart above compares the circulating supply and maximum supply of Ethereum in terms of the number of tokens.
125
+ """
126
+ )
127
+ st.plotly_chart(fig)
128
+
129
+ # Show new Ethereum tokens created in the last 24 hours with market cap > $20,000
130
+ new_tokens = get_new_tokens()
131
+ if new_tokens:
132
+ st.markdown("## New Ethereum Tokens Created in the Last 24 Hours (Market Cap > $20,000)")
133
+ for coin_token, timestamp, market_cap in new_tokens:
134
+ time_created = pd.to_datetime(timestamp, unit="ms").strftime("%H:%M:%S")
135
+ st.write(f"COIN TOKEN: {coin_token}, TIME CREATED: {time_created}, MARKET CAP: ${market_cap/1e6:.1f}MM")
136
+ else:
137
+ st.write("No new Ethereum tokens with market cap > $20,000 created in the last 24 hours.")
138
+
139
+
140
+ def tab3():
141
+ ethereum_data = get_ethereum_data()
142
+ if ethereum_data:
143
+ response = requests.get(f"{API_URL}/coins/ethereum/market_chart", params={"vs_currency": "usd", "days": "30"})
144
+ price_history = response.json()
145
+ df_price_history = pd.DataFrame(price_history["prices"], columns=["date", "price"])
146
+ df_price_history["date"] = pd.to_datetime(df_price_history["date"], unit="ms")
147
+
148
+ st.markdown("## ethereum Price History")
149
+ fig = px.line(df_price_history, x="date", y="price", title="ethereum Price History")
150
+ fig.update_layout(xaxis_title="Date", yaxis_title="Price (USD)")
151
+ st.plotly_chart(fig)
152
+ st.markdown(
153
+ """
154
+ The line chart above shows the historical price trend of ethereum over the last 30 days.
155
+ """
156
+ )
157
+
158
+ col1, col2 = st.columns(2)
159
+ with col1:
160
+
161
+ price_stats = df_price_history["price"].describe()
162
+ st.markdown("## Price Statistics")
163
+ st.write(price_stats)
164
+
165
+ with col2:
166
+ st.markdown("## Price Distribution")
167
+ fig_hist = px.histogram(df_price_history, x="price", nbins=20, title="Histogram of Price Distribution")
168
+ fig_hist.update_layout(xaxis_title="Price (USD)", yaxis_title="Count")
169
+ st.plotly_chart(fig_hist)
170
+ st.markdown(
171
+ """
172
+ The histogram above displays the distribution of ethereum prices over the last 30 days.
173
+ """
174
+ )
175
+
176
+ else:
177
+ st.write("Failed to retrieve ethereum data")
178
+
179
+
180
+
181
+ def tab4():
182
+ ethereum_data = get_ethereum_data()
183
+ if ethereum_data:
184
+ response = requests.get(f"{API_URL}/coins/ethereum/market_chart", params={"vs_currency": "usd", "days": "30"})
185
+ price_history = response.json()
186
+ df_price_history = pd.DataFrame(price_history["prices"], columns=["date", "price"])
187
+ df_price_history["date"] = pd.to_datetime(df_price_history["date"], unit="ms")
188
+
189
+ # Perform predictions
190
+ days = 30
191
+ lr_future_dates, lr_future_predictions, rf_future_dates, rf_future_predictions = predict_price(df_price_history, days)
192
+
193
+ # Visualize predictions using line charts
194
+ st.markdown("## Price Predictions")
195
+ st.subheader("Linear Regression Prediction")
196
+ df_lr_predicted = pd.DataFrame({"Date": lr_future_dates, "Predicted Price": lr_future_predictions})
197
+ st.line_chart(df_lr_predicted, x="Date", y="Predicted Price")
198
+
199
+ st.subheader("Random Forest Regression Prediction")
200
+ df_rf_predicted = pd.DataFrame({"Date": rf_future_dates, "Predicted Price": rf_future_predictions})
201
+ st.line_chart(df_rf_predicted, x="Date", y="Predicted Price")
202
+
203
+ # Additional Visualization: Combined Line Chart for Actual and Predicted Prices
204
+ df_combined = pd.concat([df_price_history, df_lr_predicted.rename(columns={"Predicted Price": "price"})])
205
+ df_combined["Type"] = ["Actual"] * len(df_price_history) + ["Predicted (LR)"] * len(df_lr_predicted)
206
+ fig_combined = px.line(df_combined, x="date", y="price", color="Type", title="Actual vs. Predicted (LR) Prices")
207
+ fig_combined.update_layout(xaxis_title="Date", yaxis_title="Price (USD)")
208
+ st.plotly_chart(fig_combined)
209
+
210
+ # Add text explanation for predictions
211
+ st.markdown("## Predictions Explanation")
212
+ st.write(
213
+ """
214
+ The price predictions are estimated using regression models: Linear Regression (LR) and Random Forest Regression (RF).
215
+ The line charts show the predicted prices over the next 30 days based on historical price data.
216
+ """
217
+ )
218
+
219
+ else:
220
+ st.write("Failed to retrieve ethereum data")
221
+
222
+ #tab5
223
+ RSS_FEED_URLS = {
224
+ "CryptoNews": "https://cryptonews.com/news/feed/",
225
+ "CoinDesk": "https://www.coindesk.com/feed",
226
+ "CryptoSlate": "https://cryptoslate.com/feed/",
227
+ # Add more RSS feed URLs here
228
+ }
229
+
230
+ def fetch_latest_news(url):
231
+ feed = feedparser.parse(url)
232
+ entries = feed.entries[:5] # Fetching the latest 5 news entries
233
+ return entries
234
+
235
+ def filter_news_by_keyword(entries, keyword):
236
+ filtered_entries = []
237
+ for entry in entries:
238
+ if keyword.lower() in entry.title.lower() or keyword.lower() in entry.summary.lower():
239
+ filtered_entries.append(entry)
240
+ return filtered_entries
241
+
242
+ def display_news_entry(entry):
243
+ st.markdown(f"## {entry.title}")
244
+ st.write(entry.summary)
245
+ st.write(f"Published on: {entry.published}")
246
+ st.write("---")
247
+
248
+ def tab5():
249
+ selected_feeds = st.multiselect("Select RSS Feeds", list(RSS_FEED_URLS.keys()), default=["CryptoNews"])
250
+ filter_keyword = st.text_input("Filter by keyword (e.g., ethereum)")
251
+
252
+ for feed in selected_feeds:
253
+ st.markdown(f"### {feed} News")
254
+
255
+ if feed in RSS_FEED_URLS:
256
+ entries = fetch_latest_news(RSS_FEED_URLS[feed])
257
+
258
+ if filter_keyword:
259
+ entries = filter_news_by_keyword(entries, filter_keyword)
260
+
261
+ for entry in entries:
262
+ display_news_entry(entry)
263
+ else:
264
+ st.write(f"No RSS feed URL found for {feed}")
265
+
266
+ def tab6():
267
+ st.header("Download script")
268
+ st.markdown(
269
+ """
270
+ download the standalone python script to print new tokens
271
+ """
272
+ )
273
+ st.image("eth.PNG")
274
+ password_input = st.text_input('Enter Password', type='password')
275
+ if authenticate(password_input):
276
+ # Contents of the get_new_coins.py file
277
+ script_content = """
278
+ import requests
279
+ import pandas as pd
280
+
281
+ API_URL = "https://api.coingecko.com/api/v3"
282
+
283
+ def float_to_hex(f):
284
+ _, hex_representation = f.hex().split('x')
285
+ return "0x" + hex_representation
286
+
287
+ def get_new_tokens():
288
+ response = requests.get(f"{API_URL}/coins/ethereum/market_chart", params={"vs_currency": "usd", "days": 1})
289
+ data = response.json()
290
+
291
+ new_tokens = []
292
+ for token in data["market_caps"]:
293
+ timestamp, market_cap = token
294
+ if market_cap > 20000:
295
+ coin_token = data["prices"][data["market_caps"].index(token)][1]
296
+ coin_token_hex = float_to_hex(coin_token)
297
+ new_tokens.append((coin_token_hex, timestamp, market_cap))
298
+ return new_tokens
299
+
300
+ if __name__ == "__main__":
301
+ new_tokens = get_new_tokens()
302
+ if new_tokens:
303
+ print("New Ethereum Tokens Created in the Last 24 Hours (Market Cap > $20,000)")
304
+ for coin_token, timestamp, market_cap in new_tokens:
305
+ time_created = pd.to_datetime(timestamp, unit="ms").strftime("%H:%M:%S")
306
+ print(f"COIN: {coin_token}, TIME CREATED: {time_created}, MARKET CAP: ${market_cap/1e6:.1f}MM")
307
+ else:
308
+ print("No new Ethereum tokens with market cap > $20,000 created in the last 24 hours.")
309
+ """
310
+
311
+ # Display the content of the script in the app
312
+ st.code(script_content, language="python")
313
+
314
+ # Download link for the script
315
+ file_name = "get_new_coins.py"
316
+ st.download_button(
317
+ label="Download get_new_coins.py",
318
+ data=script_content,
319
+ file_name=file_name,
320
+ mime="text/plain",
321
+ )
322
+ else:
323
+ # Password is incorrect, show an error message
324
+ st.error('Invalid password. Access denied.')
325
+
326
+ def main():
327
+ st.set_page_config(page_title="ethereum Dashboard", page_icon=":memo:", layout="wide")
328
+ tabs = ["Intro", "ethereum Information", "ethereum Price History", "Price Predictions", "News", "Download Script"]
329
+
330
+ with st.sidebar:
331
+
332
+ current_tab = option_menu("Select a Tab", tabs, menu_icon="cast")
333
+
334
+ tab_functions = {
335
+ "Intro": tab1,
336
+ "ethereum Information": tab2,
337
+ "ethereum Price History": tab3,
338
+ "Price Predictions": tab4,
339
+ "News": tab5,
340
+ "Download Script": tab6,
341
+ }
342
+
343
+ if current_tab in tab_functions:
344
+ tab_functions[current_tab]()
345
+
346
+
347
+
348
+ if __name__ == "__main__":
349
+ main()
eth.PNG ADDED
get_new_coins.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import pandas as pd
3
+
4
+ API_URL = "https://api.coingecko.com/api/v3"
5
+
6
+ def float_to_hex(f):
7
+ _, hex_representation = f.hex().split('x')
8
+ return "0x" + hex_representation
9
+
10
+ def get_new_tokens():
11
+ response = requests.get(f"{API_URL}/coins/ethereum/market_chart", params={"vs_currency": "usd", "days": 1})
12
+ data = response.json()
13
+
14
+ new_tokens = []
15
+ for token in data["market_caps"]:
16
+ timestamp, market_cap = token
17
+ if market_cap > 20000:
18
+ coin_token = data["prices"][data["market_caps"].index(token)][1]
19
+ coin_token_hex = float_to_hex(coin_token)
20
+ new_tokens.append((coin_token_hex, timestamp, market_cap))
21
+
22
+ new_tokens.sort(key=lambda x: x[1], reverse=True)
23
+
24
+ return new_tokens
25
+
26
+ if __name__ == "__main__":
27
+ new_tokens = get_new_tokens()
28
+ if new_tokens:
29
+ print("New Ethereum Tokens Created in the Last 24 Hours (Market Cap > $20,000)")
30
+ for coin_token, timestamp, market_cap in new_tokens:
31
+ time_created = pd.to_datetime(timestamp, unit="ms").strftime("%H:%M:%S")
32
+ print(f"COIN: {coin_token}, TIME CREATED: {time_created}, MARKET CAP: ${market_cap/1e6:.1f}MM")
33
+ else:
34
+ print("No new Ethereum tokens with market cap > $20,000 created in the last 24 hours.")
get_new_coins_auto.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import pandas as pd
3
+ import time
4
+
5
+ API_URL = "https://api.coingecko.com/api/v3"
6
+
7
+ def float_to_hex(f):
8
+ _, hex_representation = f.hex().split('x')
9
+ return "0x" + hex_representation
10
+
11
+ def get_new_tokens():
12
+ response = requests.get(f"{API_URL}/coins/ethereum/market_chart", params={"vs_currency": "usd", "days": 1})
13
+ data = response.json()
14
+
15
+ new_tokens = []
16
+ for token in data["market_caps"]:
17
+ timestamp, market_cap = token
18
+ if market_cap > 20000:
19
+ coin_token = data["prices"][data["market_caps"].index(token)][1]
20
+ coin_token_hex = float_to_hex(coin_token)
21
+ new_tokens.append((coin_token_hex, timestamp, market_cap))
22
+
23
+ new_tokens.sort(key=lambda x: x[1], reverse=True)
24
+
25
+ return new_tokens
26
+
27
+ if __name__ == "__main__":
28
+ while True:
29
+ new_tokens = get_new_tokens()
30
+ if new_tokens:
31
+ print("New Ethereum Tokens Created in the Last 24 Hours (Market Cap > $20,000)")
32
+ for coin_token, timestamp, market_cap in new_tokens:
33
+ time_created = pd.to_datetime(timestamp, unit="ms").strftime("%H:%M:%S")
34
+ print(f"COIN: {coin_token}, TIME CREATED: {time_created}, MARKET CAP: ${market_cap/1e6:.1f}MM")
35
+ else:
36
+ print("No new Ethereum tokens with market cap > $20,000 created in the last 24 hours.")
37
+
38
+ # Wait for 60 seconds before updating again
39
+ time.sleep(60)
markup.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def real_estate_app():
2
+ return """
3
+ <h3 style='text-align: center;'>Introduction</h3>
4
+
5
+ <p>This app allows you to view info about ethereum as well as predicted prices</p>
6
+
7
+ <h4>Information:</h4>
8
+ <ul>
9
+ <li><b>Real-Time Price Tracking:</b> You can view the current price of ethereum and track its fluctuations over time.</li>
10
+ <li><b>Market Data Analysis:</b> Analyze the market trends, trading volume, and other key metrics related to ethereum.</li>
11
+ </ul>
12
+ </div>
13
+ """
14
+
15
+ def real_estate_app_hf():
16
+ return """
17
+ <div style='text-align: left;'>
18
+ <h3 style='text-align: center;'>About this Demo</h3>
19
+ <br>
20
+ <h4>How to use:</h4>
21
+ <ul>
22
+ <li><b>Price Tracking:</b> The app will automatically fetch and display the latest price of ethereum. You can also view historical price data using interactive charts.</li>
23
+ <li><b>Market Analysis:</b> Explore market indicators such as trading volume, market capitalization, and price change percentage. Visualize these metrics through graphs and charts.</li>
24
+ </ul>
25
+ <br>
26
+ </div>
27
+ """
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ streamlit_option_menu
4
+ plotly
5
+ scikit-learn
6
+ feedparser