File size: 1,052 Bytes
c4bc860
 
ab205a7
 
c4bc860
6d2c491
c38663e
6d2c491
1a505ec
 
 
 
 
 
 
 
c4bc860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle
import sys
import subprocess

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'xgboost sklearn pymystem3 pandas'])

import pandas as pd
from sklearn.utils import shuffle
from sklearn.feature_extraction.text import TfidfVectorizer
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split
import pymystem3
from tqdm import tqdm

# Load the model from the file
with open('xgb_model.pkl', 'rb') as file:
    model = pickle.load(file)

with open('tfidf_vectorizer.pkl', 'rb') as file:
    vectorizer = pickle.load(file)


def predict(text):
    # Transform the text using the loaded vectorizer
    text_transformed = vectorizer.transform([text])

    # Make prediction using the loaded model
    prediction = model.predict(text_transformed)[0]

    return prediction


# Create a Gradio interface
input_text = gr.inputs.Textbox(label="Input Text")
output_text = gr.outputs.Textbox(label="Prediction")

gr.Interface(fn=predict, inputs=input_text, outputs=output_text).launch()