Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,79 +1,93 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import tensorflow as tf
|
| 5 |
-
import joblib
|
| 6 |
-
from tensorflow.keras.models import load_model
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if len(data) < 60:
|
| 17 |
-
mean_value = np.mean(data) # Compute mean of given prices
|
| 18 |
-
data = data + [mean_value] * (60 - len(data)) # Fill missing spots
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
return scaled_data.reshape(1, 60, 1) # Reshape for LSTM
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def batch_predict(file):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
-
# Gradio UI
|
| 59 |
-
demo = gr.Interface(
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
)
|
| 70 |
|
| 71 |
-
batch_demo = gr.Interface(
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
)
|
| 78 |
|
| 79 |
-
gr.TabbedInterface([demo, batch_demo], ["Single Prediction", "Batch Prediction"]).launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def message():
|
| 4 |
+
return "🚧 Under Construction 🚧\n\nCheck back soon!"
|
| 5 |
|
| 6 |
+
demo = gr.Interface(
|
| 7 |
+
fn=message,
|
| 8 |
+
inputs=[],
|
| 9 |
+
outputs=gr.Textbox(label="Status"),
|
| 10 |
+
title="Site Under Construction",
|
| 11 |
+
description="This application is currently under development. Please check back later!"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
demo.launch()
|
| 15 |
+
# import gradio as gr
|
| 16 |
+
# import numpy as np
|
| 17 |
+
# import pandas as pd
|
| 18 |
+
# import tensorflow as tf
|
| 19 |
+
# import joblib
|
| 20 |
+
# from tensorflow.keras.models import load_model
|
| 21 |
|
| 22 |
+
# # Load the trained LSTM model
|
| 23 |
+
# model = load_model("lstm_gru_model5.h5")
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# # Load the MinMaxScaler
|
| 26 |
+
# scaler = joblib.load("forex_scaler222.pkl")
|
|
|
|
| 27 |
|
| 28 |
+
# def preprocess_input(data):
|
| 29 |
+
# """Preprocess input data for LSTM model."""
|
| 30 |
+
# if len(data) < 60:
|
| 31 |
+
# mean_value = np.mean(data) # Compute mean of given prices
|
| 32 |
+
# data = data + [mean_value] * (60 - len(data)) # Fill missing spots
|
| 33 |
|
| 34 |
+
# data = np.array(data).reshape(1, -1) # Reshape for MinMaxScaler
|
| 35 |
+
# scaled_data = scaler.transform(data) # Scale the input
|
| 36 |
+
# return scaled_data.reshape(1, 60, 1) # Reshape for LSTM
|
| 37 |
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# def predict_forex(prices):
|
| 41 |
+
# """Predict the next forex price based on the input sequence."""
|
| 42 |
+
# try:
|
| 43 |
+
# input_data = [float(price) for price in prices.split(",")]
|
| 44 |
|
| 45 |
+
# # Ensure enough input data
|
| 46 |
+
# if len(input_data) < 60:
|
| 47 |
+
# return "Please provide at least 60 previous forex prices."
|
| 48 |
|
| 49 |
+
# # Use last 60 prices
|
| 50 |
+
# preprocessed_data = preprocess_input(input_data[-60:])
|
| 51 |
+
# prediction = model.predict(preprocessed_data)
|
| 52 |
+
|
| 53 |
+
# # Convert back to original scale
|
| 54 |
+
# predicted_price = scaler.inverse_transform(prediction)[0][0]
|
| 55 |
+
# return f"Predicted Next Price: {predicted_price:.5f}"
|
| 56 |
+
# except Exception as e:
|
| 57 |
+
# return f"Error: {str(e)}"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# def batch_predict(file):
|
| 61 |
+
# """Batch prediction for CSV files."""
|
| 62 |
+
# try:
|
| 63 |
+
# df = pd.read_csv(file)
|
| 64 |
+
# if "prices" not in df.columns:
|
| 65 |
+
# return "CSV must have a 'prices' column with historical data."
|
| 66 |
|
| 67 |
+
# df["predictions"] = df["prices"].rolling(window=10).apply(lambda x: predict_forex(",".join(map(str, x))) if len(x) == 10 else None)
|
| 68 |
+
# return df.dropna()
|
| 69 |
+
# except Exception as e:
|
| 70 |
+
# return f"Error: {str(e)}"
|
| 71 |
|
| 72 |
+
# # Gradio UI
|
| 73 |
+
# demo = gr.Interface(
|
| 74 |
+
# fn=predict_forex,
|
| 75 |
+
# inputs=gr.Textbox(label="Enter last 10 forex prices (comma-separated)"),
|
| 76 |
+
# outputs=gr.Textbox(label="Predicted Next Price"),
|
| 77 |
+
# title="Forex Price Predictor",
|
| 78 |
+
# description="Enter the last 10 forex prices to predict the next price. Upload CSV for batch predictions.",
|
| 79 |
+
# examples=[
|
| 80 |
+
# ["1.2345,1.2350,1.2360,1.2370,1.2380,1.2390,1.2400,1.2410,1.2420,1.2430"]
|
| 81 |
+
# ],
|
| 82 |
+
# allow_flagging="never"
|
| 83 |
+
# )
|
| 84 |
|
| 85 |
+
# batch_demo = gr.Interface(
|
| 86 |
+
# fn=batch_predict,
|
| 87 |
+
# inputs=gr.File(label="Upload CSV"),
|
| 88 |
+
# outputs=gr.Dataframe(label="Predictions"),
|
| 89 |
+
# title="Batch Prediction",
|
| 90 |
+
# description="Upload a CSV with a 'prices' column for batch predictions."
|
| 91 |
+
# )
|
| 92 |
|
| 93 |
+
# gr.TabbedInterface([demo, batch_demo], ["Single Prediction", "Batch Prediction"]).launch()
|