NLP_ROSATOM / app.py
Efimov6886's picture
Update app.py
c38663e
raw
history blame
1.05 kB
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()