import gdown import joblib import requests from gensim.models import KeyedVectors # Function to download files from Google Drive using gdown def download_file_from_google_drive(file_id, destination): gdown.download(f"https://drive.google.com/uc?export=download&id={file_id}", destination, quiet=False) # Download models from Google Drive using the file IDs download_file_from_google_drive('1iN8Hp4cJfEZc2s4vBij7MrKksGRWWJpL', 'word2vec_model.model') download_file_from_google_drive('19-vsY_0Gy5EbPOd9qO4mf8rjKvndJfry', 'log_reg_model.pkl') download_file_from_google_drive('1XR_jMg2WpZPdzpiB7ZXL-iUGHA0l4S3J', 'nb_model.pkl') # Load Word2Vec model (make sure it's in binary format) word2vec_model = KeyedVectors.load_word2vec_format('word2vec_model.model', binary=True) # Load Logistic Regression model log_reg_model = joblib.load('log_reg_model.pkl') # Load Naive Bayes model nb_model = joblib.load('nb_model.pkl') # Function for Word2Vec similarity def get_similarity(word1, word2): try: similarity_score = word2vec_model.similarity(word1, word2) return similarity_score except KeyError: return "One or both words are not in the vocabulary" # Function for Logistic Regression prediction def log_reg_predict(text): prediction = log_reg_model.predict([text]) return prediction.tolist() # Function for Naive Bayes prediction def nb_predict(text): prediction = nb_model.predict([text]) return prediction.tolist() # Gradio interfaces for each model iface1 = gr.Interface(fn=get_similarity, inputs=[gr.Textbox(label="Word 1"), gr.Textbox(label="Word 2")], outputs="text", live=True, title="Word2Vec Similarity") iface2 = gr.Interface(fn=log_reg_predict, inputs="text", outputs="text", live=True, title="Logistic Regression Prediction") iface3 = gr.Interface(fn=nb_predict, inputs="text", outputs="text", live=True, title="Naive Bayes Prediction") # Launch interfaces iface1.launch() iface2.launch() iface3.launch()