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()