CoolFace
Apppublic

Reethika23/sp500_UI

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py50 linesDownload Raw Back to root
1import gradio as gr2from PIL import Image3import requests4import hopsworks5import joblib6import pandas as pd7import numpy as np8 9 10project = hopsworks.login()11fs = project.get_feature_store()12 13mr = project.get_model_registry()14model = mr.get_model("sp500_model", version=1)15model_dir = model.download()16model = joblib.load(model_dir + "/sp500_model.pkl")17print("Model downloaded")18 19def sp500(open, high, low, volume):20    print("Calling function")21    df = pd.DataFrame([[open, high, low, volume]],22                      columns=["open", "high","low", "volume"])23    print("Predicting")24    print(df)25    # 'res' is a list of predictions returned as the label.26    res = model.predict(df)27    # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want 28    # the first element.29    print(res[0])30    try:31        return res[0]32    except Exception as e:33        print(f"Error downloading or opening the image: {e}")34        return None35 36demo = gr.Interface(37    fn=sp500,38    title="SP500 Stock Analysis",39    description="Experiment with Various sp500 parameters to predict the close price.",40    allow_flagging="never",41    inputs=[42        gr.Number(label="open"),43        gr.Number(label="high"),44        gr.Number(label="low"),45        gr.Number(label="volume"),46    ],47    outputs="text"48)49 50demo.launch(debug=True)