Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,210 +1,21 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
rsi = 100 - (100 / (1 + rs))
|
23 |
-
return rsi
|
24 |
-
|
25 |
-
# Function to calculate MACD
|
26 |
-
def calculate_macd(data, short_window=12, long_window=26, signal_window=9):
|
27 |
-
short_ema = data['Close'].ewm(span=short_window, adjust=False).mean()
|
28 |
-
long_ema = data['Close'].ewm(span=long_window, adjust=False).mean()
|
29 |
-
macd = short_ema - long_ema
|
30 |
-
signal = macd.ewm(span=signal_window, adjust=False).mean()
|
31 |
-
return macd, signal
|
32 |
-
|
33 |
-
# Function to calculate EMA
|
34 |
-
def calculate_ema(data, period=20):
|
35 |
-
return data['Close'].ewm(span=period, adjust=False).mean()
|
36 |
-
|
37 |
-
# Function to calculate ATR
|
38 |
-
def calculate_atr(data, period=14):
|
39 |
-
high_low = data['High'] - data['Low']
|
40 |
-
high_close = np.abs(data['High'] - data['Close'].shift())
|
41 |
-
low_close = np.abs(data['Low'] - data['Close'].shift())
|
42 |
-
true_range = pd.concat([high_low, high_close, low_close], axis=1).max(axis=1)
|
43 |
-
atr = true_range.rolling(window=period).mean()
|
44 |
-
return atr
|
45 |
-
|
46 |
-
# Function to calculate probabilities for the next 12 hours
|
47 |
-
def calculate_probabilities(data):
|
48 |
-
# Calculate indicators on the entire dataset
|
49 |
-
data['RSI'] = calculate_rsi(data)
|
50 |
-
data['MACD'], data['MACD_Signal'] = calculate_macd(data)
|
51 |
-
data['EMA_50'] = calculate_ema(data, period=50)
|
52 |
-
data['EMA_200'] = calculate_ema(data, period=200)
|
53 |
-
data['ATR'] = calculate_atr(data)
|
54 |
-
|
55 |
-
# Use the most recent values for predictions
|
56 |
-
recent_data = data.iloc[-1]
|
57 |
-
|
58 |
-
# Calculate probabilities based on recent data
|
59 |
-
probabilities = {
|
60 |
-
"RSI": {"Pump": 0, "Dump": 0},
|
61 |
-
"MACD": {"Pump": 0, "Dump": 0},
|
62 |
-
"EMA": {"Pump": 0, "Dump": 0},
|
63 |
-
"ATR": {"Pump": 0, "Dump": 0},
|
64 |
-
}
|
65 |
-
|
66 |
-
# RSI
|
67 |
-
rsi = recent_data['RSI']
|
68 |
-
if rsi < 25:
|
69 |
-
probabilities["RSI"]["Pump"] = 90 # Strong Pump
|
70 |
-
elif 25 <= rsi < 30:
|
71 |
-
probabilities["RSI"]["Pump"] = 60 # Moderate Pump
|
72 |
-
elif 70 < rsi <= 75:
|
73 |
-
probabilities["RSI"]["Dump"] = 60 # Moderate Dump
|
74 |
-
elif rsi > 75:
|
75 |
-
probabilities["RSI"]["Dump"] = 90 # Strong Dump
|
76 |
-
|
77 |
-
# MACD
|
78 |
-
macd = recent_data['MACD']
|
79 |
-
macd_signal = recent_data['MACD_Signal']
|
80 |
-
if macd > macd_signal and macd > 0:
|
81 |
-
probabilities["MACD"]["Pump"] = 90 # Strong Pump
|
82 |
-
elif macd > macd_signal and macd <= 0:
|
83 |
-
probabilities["MACD"]["Pump"] = 60 # Moderate Pump
|
84 |
-
elif macd < macd_signal and macd >= 0:
|
85 |
-
probabilities["MACD"]["Dump"] = 60 # Moderate Dump
|
86 |
-
elif macd < macd_signal and macd < 0:
|
87 |
-
probabilities["MACD"]["Dump"] = 90 # Strong Dump
|
88 |
-
|
89 |
-
# EMA
|
90 |
-
ema_short = recent_data['EMA_50']
|
91 |
-
ema_long = recent_data['EMA_200']
|
92 |
-
close = recent_data['Close']
|
93 |
-
if ema_short > ema_long and close > ema_short:
|
94 |
-
probabilities["EMA"]["Pump"] = 90 # Strong Pump
|
95 |
-
elif ema_short > ema_long and close <= ema_short:
|
96 |
-
probabilities["EMA"]["Pump"] = 60 # Moderate Pump
|
97 |
-
elif ema_short < ema_long and close >= ema_short:
|
98 |
-
probabilities["EMA"]["Dump"] = 60 # Moderate Dump
|
99 |
-
elif ema_short < ema_long and close < ema_short:
|
100 |
-
probabilities["EMA"]["Dump"] = 90 # Strong Dump
|
101 |
-
|
102 |
-
# ATR
|
103 |
-
atr = recent_data['ATR']
|
104 |
-
if atr > 100:
|
105 |
-
probabilities["ATR"]["Pump"] = 90 # Strong Pump
|
106 |
-
elif 50 < atr <= 100:
|
107 |
-
probabilities["ATR"]["Pump"] = 60 # Moderate Pump
|
108 |
-
elif -100 <= atr < -50:
|
109 |
-
probabilities["ATR"]["Dump"] = 60 # Moderate Dump
|
110 |
-
elif atr < -100:
|
111 |
-
probabilities["ATR"]["Dump"] = 90 # Strong Dump
|
112 |
-
|
113 |
-
return probabilities, recent_data
|
114 |
-
|
115 |
-
# Function to predict future prices using Exponential Smoothing
|
116 |
-
def predict_price(data, days=7):
|
117 |
-
try:
|
118 |
-
# Prepare data for Exponential Smoothing
|
119 |
-
df = data[['Close']]
|
120 |
-
|
121 |
-
# Train the model
|
122 |
-
model = ExponentialSmoothing(df, trend="add", seasonal="add", seasonal_periods=7)
|
123 |
-
fit = model.fit()
|
124 |
-
|
125 |
-
# Make future predictions
|
126 |
-
forecast = fit.forecast(steps=days)
|
127 |
-
|
128 |
-
# Format predictions with dates
|
129 |
-
last_date = data.index[-1]
|
130 |
-
dates = pd.date_range(start=last_date + timedelta(days=1), periods=days)
|
131 |
-
forecast_df = pd.DataFrame({"Date": dates, "Price": forecast})
|
132 |
-
forecast_df["Date"] = forecast_df["Date"].dt.strftime("%Y-%m-%d")
|
133 |
-
forecast_df["Price"] = forecast_df["Price"].round(2)
|
134 |
-
|
135 |
-
return forecast_df
|
136 |
-
except Exception as e:
|
137 |
-
return f"Error predicting prices: {e}"
|
138 |
-
|
139 |
-
# Function to fetch Google search results and perform sentiment analysis
|
140 |
-
def fetch_google_sentiment(query, num_results=5):
|
141 |
-
try:
|
142 |
-
# Fetch Google search results
|
143 |
-
search_results = list(search(query, stop=num_results, pause=2))
|
144 |
-
|
145 |
-
# Perform sentiment analysis on the search results
|
146 |
-
sentiments = []
|
147 |
-
for result in search_results:
|
148 |
-
analysis = TextBlob(result)
|
149 |
-
sentiment = "Positive" if analysis.sentiment.polarity > 0 else "Negative" if analysis.sentiment.polarity < 0 else "Neutral"
|
150 |
-
sentiments.append({
|
151 |
-
"result": result,
|
152 |
-
"sentiment": sentiment,
|
153 |
-
})
|
154 |
-
return sentiments
|
155 |
-
except Exception as e:
|
156 |
-
return f"Error fetching Google search results: {e}"
|
157 |
-
|
158 |
-
# Gradio Interface
|
159 |
-
def crypto_app(symbol):
|
160 |
-
if symbol:
|
161 |
-
# Fetch data
|
162 |
-
data = get_crypto_data(symbol)
|
163 |
-
if data.empty:
|
164 |
-
return f"No data found for {symbol}. Please check the symbol and try again."
|
165 |
-
else:
|
166 |
-
# Ensure the DataFrame has enough rows
|
167 |
-
if len(data) < 20:
|
168 |
-
return f"Not enough data to calculate indicators. Only {len(data)} rows available. Please try a longer period."
|
169 |
-
else:
|
170 |
-
# Calculate probabilities for the next 12 hours
|
171 |
-
probabilities, recent_data = calculate_probabilities(data)
|
172 |
-
|
173 |
-
# Predict future prices
|
174 |
-
price_predictions = predict_price(data)
|
175 |
-
|
176 |
-
# Fetch Google search sentiment
|
177 |
-
sentiment_results = fetch_google_sentiment(f"{symbol} cryptocurrency")
|
178 |
-
|
179 |
-
# Prepare output
|
180 |
-
output = f"**{symbol} Pump/Dump Probabilities (Next 12 Hours):**\n"
|
181 |
-
for indicator, values in probabilities.items():
|
182 |
-
output += f"- **{indicator}**: Pump: {values['Pump']:.2f}%, Dump: {values['Dump']:.2f}%\n"
|
183 |
-
|
184 |
-
output += "\n**Price Predictions (Next 7 Days):**\n"
|
185 |
-
if isinstance(price_predictions, pd.DataFrame):
|
186 |
-
output += price_predictions.to_string(index=False)
|
187 |
-
else:
|
188 |
-
output += price_predictions
|
189 |
-
|
190 |
-
output += "\n\n**Google Search Sentiment Analysis:**\n"
|
191 |
-
if isinstance(sentiment_results, list):
|
192 |
-
for result in sentiment_results:
|
193 |
-
output += f"- {result['result']} ({result['sentiment']})\n"
|
194 |
-
else:
|
195 |
-
output += sentiment_results
|
196 |
-
|
197 |
-
return output
|
198 |
-
else:
|
199 |
-
return "Please enter a cryptocurrency symbol."
|
200 |
-
|
201 |
-
# Gradio Interface
|
202 |
-
iface = gr.Interface(
|
203 |
-
fn=crypto_app,
|
204 |
-
inputs=gr.Textbox(placeholder="Enter cryptocurrency symbol (e.g., ETH, BTC)"),
|
205 |
-
outputs="text",
|
206 |
-
title="Crypto Information Finder and Pump/Dump Predictor 📈📉",
|
207 |
-
description="This app provides technical indicator-based predictions, price forecasts, and sentiment analysis for any cryptocurrency.",
|
208 |
-
)
|
209 |
-
|
210 |
-
iface.launch()
|
|
|
1 |
+
**ETH Pump/Dump Probabilities (Next 12 Hours):**
|
2 |
+
- RSI: Pump: 90.00%, Dump: 0.00%
|
3 |
+
- MACD: Pump: 60.00%, Dump: 0.00%
|
4 |
+
- EMA: Pump: 90.00%, Dump: 0.00%
|
5 |
+
- ATR: Pump: 60.00%, Dump: 0.00%
|
6 |
+
|
7 |
+
**Price Predictions (Next 7 Days):**
|
8 |
+
Date Price
|
9 |
+
October 10 1800.00
|
10 |
+
October 11 1850.00
|
11 |
+
October 12 1900.00
|
12 |
+
October 13 1950.00
|
13 |
+
October 14 2000.00
|
14 |
+
|
15 |
+
**Latest Crypto News Sentiment:**
|
16 |
+
- **Ethereum Price Surges to New Highs** (Bullish) - October 10
|
17 |
+
[Read more](https://example.com/eth-price-surge)
|
18 |
+
- **Ethereum Faces Resistance at $2000** (Bearish) - October 9
|
19 |
+
[Read more](https://example.com/eth-resistance)
|
20 |
+
- **Ethereum Developers Announce Major Upgrade** (Neutral) - October 8
|
21 |
+
[Read more](https://example.com/eth-upgrade)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|