Spaces:
Runtime error
Runtime error
File size: 2,239 Bytes
8de7ea0 e7e0370 b5ac0f9 e7e0370 8de7ea0 b5ac0f9 8de7ea0 b5ac0f9 8de7ea0 b5ac0f9 e7e0370 8de7ea0 e7e0370 | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 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()
|