Stock_Predictor / app.py
PebinAPJ's picture
Rename app .py to app.py
7e16209 verified
raw
history blame
1.19 kB
# -*- coding: utf-8 -*-
"""app.py
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1LNqeNTVe-zMc4YfmFi5S5fPJJcv572lx
"""
import gradio as gr
import pickle
import numpy as np
# Load the trained model
with open("stock_model.pkl", "rb") as file:
model = pickle.load(file)
# Define the prediction function
def predict_stock_price(features):
try:
# Convert input string to a NumPy array
features_array = np.array([float(x) for x in features.split(",")]).reshape(1, -1)
# Predict using the model
prediction = model.predict(features_array)
return f"Predicted Stock Price: {prediction[0]}"
except Exception as e:
return f"Error: {e}"
# Create a Gradio Interface
interface = gr.Interface(
fn=predict_stock_price, # Function to call
inputs=gr.Textbox(label="Input Features (comma-separated)", placeholder="1.5, 2.3, 0.7, 5.4"),
outputs=gr.Textbox(label="Prediction"),
title="Stock Price Predictor",
description="Enter features as a comma-separated list to predict stock prices."
)
# Launch the Gradio app
if __name__ == "__main__":
interface.launch()