Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines78910111213141537 unmodified lines535455566 unmodified linesfrom official.nlp.data import classifier_data_libfrom official.nlp.tools import tokenizationimport joblibmodel = load_model('best_model.h5', custom_objects={'KerasLayer': hub.KerasLayer})vocab_file = model.resolved_object.vocab_file.asset_path.numpy()do_lower_case = model.resolved_object.do_lower_case.numpy()37 unmodified linesdataset = dataset.batch(32, drop_remainder=False)dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)return dataset6 unmodified lines789101112131415161718192037 unmodified lines585960616263646566676869707172737475767778798081828384858687888990919293946 unmodified linesfrom official.nlp.data import classifier_data_libfrom official.nlp.tools import tokenizationimport joblibimport zipfileimport gradio as grmodel = load_model('best_model.h5', custom_objects={'KerasLayer': hub.KerasLayer})with zipfile.ZipFile('model.zip', 'r') as zip_ref:zip_ref.extractall('model')vocab_file = model.resolved_object.vocab_file.asset_path.numpy()do_lower_case = model.resolved_object.do_lower_case.numpy()37 unmodified linesdataset = dataset.batch(32, drop_remainder=False)dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)return datasetdef launch(input):# Load the label encoderlabel_encoder = joblib.load('label_encoder.joblib')# Preprocess the new datasample_example = [input]new_data_dataset = preprocess_new_data(sample_example)# Assuming you have a model already loaded (add model loading code if needed)# Make predictions on the new datapredictions = model.predict(new_data_dataset)# Decode the predictionspredicted_classes = [label_list[np.argmax(pred)] for pred in predictions]# Print the predicted classesprint(predicted_classes)# Calculate the highest probabilitieshighest_probabilities = [max(instance) for instance in predictions]# Decode labels using the label encoderdecoded_labels = label_encoder.inverse_transform(predicted_classes)print("Most likely ISCO code is {} and probability is {}".format(decoded_labels,highest_probabilities))# Gradio Interfaceiface = gr.Interface(fn=launch,inputs=gr.inputs.Textbox(lines=2, placeholder="Enter job title and description here..."),outputs="text")# Launch the Gradio appiface.launch()
app.py+39-1