Spaces:
Runtime error
Runtime error
File size: 1,255 Bytes
c4bc860 ab205a7 5893957 c4bc860 6d2c491 576bc6a 6d2c491 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 42 43 44 45 46 |
import gradio as gr
import pickle
import sys
import subprocess
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
subprocess.check_call([sys.executable, '-m', 'pip', 'install',
'xgboost'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install',
'sklearn'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install',
'pymystem3'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install',
'pandas'])
# 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()
|