Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from tensorflow.keras.models import Sequential
|
| 4 |
+
from tensorflow.keras.layers import SimpleRNN, Dense
|
| 5 |
+
|
| 6 |
+
# 📌 Simulate an RNN model on-the-fly for demo (NOT from HF)
|
| 7 |
+
def create_dummy_rnn():
|
| 8 |
+
model = Sequential()
|
| 9 |
+
model.add(SimpleRNN(10, activation='relu', input_shape=(3, 1)))
|
| 10 |
+
model.add(Dense(1))
|
| 11 |
+
model.compile(optimizer='adam', loss='mse')
|
| 12 |
+
|
| 13 |
+
# Train on dummy increasing patterns
|
| 14 |
+
X = []
|
| 15 |
+
y = []
|
| 16 |
+
for i in range(1, 100):
|
| 17 |
+
X.append([i, i+1, i+2])
|
| 18 |
+
y.append(i+3)
|
| 19 |
+
X = np.array(X).reshape((len(X), 3, 1))
|
| 20 |
+
y = np.array(y)
|
| 21 |
+
model.fit(X, y, epochs=20, verbose=0)
|
| 22 |
+
return model
|
| 23 |
+
|
| 24 |
+
# Load dummy model (simulate download)
|
| 25 |
+
model = create_dummy_rnn()
|
| 26 |
+
|
| 27 |
+
def predict_next_number(a, b, c):
|
| 28 |
+
try:
|
| 29 |
+
x = np.array([float(a), float(b), float(c)]).reshape((1, 3, 1))
|
| 30 |
+
prediction = model.predict(x, verbose=0)[0][0]
|
| 31 |
+
return f"🔮 Predicted Next Number: {prediction:.2f}"
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"⚠️ Error: {str(e)}"
|
| 34 |
+
|
| 35 |
+
# Gradio Interface
|
| 36 |
+
inputs = [
|
| 37 |
+
gr.Number(label="First Number"),
|
| 38 |
+
gr.Number(label="Second Number"),
|
| 39 |
+
gr.Number(label="Third Number"),
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
outputs = gr.Textbox(label="Predicted Next Number")
|
| 43 |
+
|
| 44 |
+
app = gr.Interface(
|
| 45 |
+
fn=predict_next_number,
|
| 46 |
+
inputs=inputs,
|
| 47 |
+
outputs=outputs,
|
| 48 |
+
title="📈 Next Number Predictor (RNN)",
|
| 49 |
+
description="Enter 3 numbers (e.g., 1, 2, 3) and this app predicts the next number using a simple RNN!"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
app.launch()
|