import gradio as gr import torch from dual_regression_model import DualRegressionModel import transformers from transformers import pipeline from functools import partial # load the models # CLF: A-pt-bs16-dbmdz-bert-base-italian-cased clf_model_tag = "clf_model/" clf_tokenizer = transformers.AutoTokenizer.from_pretrained(clf_model_tag) clf_model = transformers.AutoModelForSequenceClassification.from_pretrained(clf_model_tag) clf_pipeline = pipeline("text-classification", model=clf_model, tokenizer=clf_tokenizer) # REG reg_model_tag = "distilbert-base-multilingual-cased" reg_model_folder = "reg_model/regression_model.pt" reg_model = DualRegressionModel(model_name_or_path=reg_model_tag) reg_model.load_model(reg_model_folder) # define the function to be used for prediction def predict(text): # predict the class clf_prediction = clf_pipeline(text)[0] # predict the coordinates reg_input = reg_model.tokenizer(text, return_tensors="pt") reg_prediction = reg_model(reg_input) latitude, longitude = reg_prediction["latitude"].item(), reg_prediction["longitude"].item() lat_min = 38 lat_max = 46 long_min = 8 long_max = 18 # return the results html_output = f"
Latitude: {latitude}
Longitude: {longitude}
' html_output += f'