Spaces:
Sleeping
Sleeping
import gradio as gr | |
import nltk | |
from nltk.corpus import stopwords | |
import joblib | |
nltk.download('punkt') | |
# Load the trained model and vectorizer outside the function for better performance | |
loaded_classifier = joblib.load("bible_or_talmud_model.pkl") | |
vectorizer = joblib.load("bible_or_talmud_vectorizer.pkl") | |
def parse_text(new_text): | |
new_text_tfidf = vectorizer.transform([new_text]) | |
prediction = loaded_classifier.predict(new_text_tfidf) | |
probabilities = loaded_classifier.predict_proba(new_text_tfidf) | |
confidence_score = max(probabilities[0]) | |
labels = {0: '讗讞专', 1: '转谞"讱', 2: '转诇诪讜讚 讘讘诇讬'} | |
predicted_label = labels[prediction[0]] | |
return predicted_label, confidence_score | |
iface = gr.Interface(fn=parse_text, inputs="text", outputs=["text", "number"], title='讙讬诇讜讬 驻住讜拽讬 讛转谞"讱 讘讗诪爪注讜转 AI', description='讛讝谉 讟拽住讟 讻讚讬 诇住讜讜讙 讗诐 讛讜讗 诪讛转谞"讱 讗讜 诇讗.') | |
iface.launch() | |