root commited on
Commit
c4bc860
·
1 Parent(s): e3ed379

Add application file

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+
5
+ # Load the model from the file
6
+ with open('xgb_model.pkl', 'rb') as file:
7
+ model = pickle.load(file)
8
+
9
+ with open('tfidf_vectorizer.pkl', 'rb') as file:
10
+ vectorizer = pickle.load(file)
11
+
12
+
13
+ def predict(text):
14
+ # Transform the text using the loaded vectorizer
15
+ text_transformed = vectorizer.transform([text])
16
+
17
+ # Make prediction using the loaded model
18
+ prediction = model.predict(text_transformed)[0]
19
+
20
+ return prediction
21
+
22
+
23
+ # Create a Gradio interface
24
+ input_text = gr.inputs.Textbox(label="Input Text")
25
+ output_text = gr.outputs.Textbox(label="Prediction")
26
+
27
+ gr.Interface(fn=predict, inputs=input_text, outputs=output_text).launch()
28
+