File size: 2,404 Bytes
3493d9e
 
 
 
 
 
 
 
 
 
 
dabe296
3493d9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import pandas as pd
import pickle
import gradio as gr

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestRegressor

# Load the saved full pipeline from the file
model_file = 'Random-Forest-Regressor.pkl'

with open(model_file, 'rb') as f_in:
    scaler, model = pickle.load(f_in)

# Define the predict function
def predict(SPX, USO, SLV, EUR_USD):
    # Create a DataFrame from the input data
    input_data = pd.DataFrame({
        'SPX': [SPX] if SPX is not None else [0],  # Replace None with default value
        'USO': [USO] if USO is not None else [0],  # Replace None with default value
        'SLV': [SLV] if SLV is not None else [0],  # Replace None with default value
        'EUR_USD': [EUR_USD] if EUR_USD is not None else [0],  # Replace None with default value
    })


        # Make predictions using the loaded logistic regression model
        #predict probabilities
    predictions = model.predict(input_data)
    #take the index of the maximum probability


    #return predictions[0]
    return(f'[Info] Predicted probabilities{predictions}')
    
# Setting Gradio App Interface
with gr.Blocks(css=".gradio-container {background-color:grey }",theme=gr.themes.Base(primary_hue='blue'),title='Uriel') as demo:
    gr.Markdown("# Gold Price prediction #\n*This App allows the user to predict the price of Gold.*")
    
    # Receiving ALL Input Data here
    gr.Markdown("**Demographic Data**")
    with gr.Row():
        gender = gr.Number(label="Standard & Poor's Index")
        SeniorCitizen = gr.Number(label="United State Oil Fund")
        Partner = gr.Number(label="Silver Price")
        Dependents = gr.Number(label="EURO_Dollar Exchange")


    # Output Prediction
    output = gr.Text(label="Outcome")
    submit_button = gr.Button("Predict")
    
    submit_button.click(fn= predict,
                        outputs= output,
                        inputs=[gender, SeniorCitizen, Partner, Dependents],
    
    ),
    
    # Add the reset and flag buttons
    def clear():
        output.value = ""
        return 'Predicted values have been reset'
         
    clear_btn = gr.Button("Reset", variant="primary")
    clear_btn.click(fn=clear, inputs=None, outputs=output)
        
 
demo.launch(inbrowser = True)