universalml commited on
Commit
c3683d1
·
verified ·
1 Parent(s): 3c2a128

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from joblib import load
2
+ import gradio as gr
3
+
4
+
5
+ MODEL_NAME = ""
6
+ loaded_model = load("model.joblib")
7
+
8
+
9
+ def prediction_function(*args):
10
+ values_list = []
11
+
12
+ for arg in args:
13
+ values_list.append(int(arg))
14
+
15
+ prediction_result = loaded_model.predict([values_list])[0]
16
+
17
+ return f"Predicted value: {prediction_result}"
18
+
19
+
20
+ def regression_inputs():
21
+ input_labels = loaded_model.input_feature_names
22
+
23
+ inputs = []
24
+ for input_label in input_labels:
25
+ value = gr.Textbox(label=input_label, type="text")
26
+ inputs.append(value)
27
+
28
+ return inputs
29
+
30
+
31
+ def regression_output():
32
+ output_label = loaded_model.output_feature_name
33
+ output = gr.Textbox(label=output_label, type="text")
34
+
35
+ return output
36
+
37
+
38
+ def create_interface():
39
+ interface = gr.Interface(
40
+ fn=prediction_function,
41
+ inputs=regression_inputs(),
42
+ outputs=regression_output(),
43
+ title=MODEL_NAME,
44
+ )
45
+
46
+ interface.launch(debug=True)
47
+
48
+
49
+ create_interface()