def tag_recommendation(): # Appeler les Inputs de la page HTML dashboard question = request.form['question'] #request.args.get('question') tags_text = '' if question is not None: question = str(question) question_tag = preprocessing(question) question_tag_df = pd.DataFrame([question_tag], columns=['question']) test_input_df = pd.concat([question_tag_df, input_df_tags_500], ignore_index=True) question_input = test_input_df['question'] vectorizer = TfidfVectorizer(tokenizer=tokenize, stop_words=stop_words, max_features=355) X_tfidf = vectorizer.fit_transform(question_input).toarray() feature_names = vectorizer.get_feature_names() X_test_question = pd.DataFrame(X_tfidf) X_test_question = X_test_question.iloc[0:1, :] X_test_question.columns = feature_names tags_num = pipeline.predict(X_test_question) mlb = MultiLabelBinarizer(classes=sorted(input_tags_500)) mlb.fit(input_tags_500) tags_text = pd.concat( [pd.Series(mlb.inverse_transform(tags_num), name='tags_num')], axis=1) tags_text = str(tags_text.values.tolist()).strip('[()]') tags_text return render_template('recommendation.html', tags=tags_text)
def update_graphs(_): """ Returns ------- list Lista de figuras que se actualizarán en la página """ figures = [] for ramo in ramos: nrc, sigla, sec = ramo.values() data, name_ = vacantes(semestre, nrc, sigla, sec) df = preprocessing(data) fig = px.sunburst(data_frame=df, path=['T_Vacante', 'Escuela'], values='Vacantes', color='T_Vacante', color_discrete_map={ 'Disponible': 'Lavender', 'Ocupado': 'Firebrick' }) fig.update_layout(margin=dict(t=30, b=30), plot_bgcolor=colors['background'], paper_bgcolor=colors['background'], font_color=colors['text']) figures.append(fig) return figures
########################################################################################## # USER INITIALIZATIONS ########################################################################################## question, options = 5, 5 # QUESTIONS AND CHOICES myAnswers = [1, 2, 0, 4, 4] # Actual Answers choiceArea = 1000 # Area of the circles img_width, img_height = 550, 600 global contours ########################################################################################## ######################################################################################### # PREPROCESSING THE IMAGE ######################################################################################### image = cv.imread('OMR 1.jpg') image = cv.resize(image, (img_width, img_height)) img_cont_2 = image.copy() Canny, Erode = functions.preprocessing(image) ############################################# try: ########################################################################################## # CONTOURS ########################################################################################## contours, img_cont = functions.get_contour(image, Canny, filters=4, draw=True, minArea=9000) # contours contains (contours, area, peri, approx, len(approx), center, bbox) # With respect to the given parameters ########################################################################################## # Verification of the contours by drawing on img_cont_2 # Checking whether marking area is given or not ########################################################################################## cv.drawContours(img_cont_2, contours[0][0], -1, (0, 0, 255), 5) if len(contours) == 2: cv.drawContours(img_cont_2, contours[1][0], -1, (255, 0, 0), 5)
from functions import preprocessing, gen_data, odeintI, get_params from matplotlib import pyplot as plt from matplotlib import gridspec net = Net() net.load_state_dict(torch.load("model")) net.eval() #VALEURS params = get_params() arange, brange, pop, n, T = params #TEST SET test_data, test_labels = gen_data(arange, brange, pop, n, T, 50) p_test_data, p_test_labels = preprocessing(test_data, test_labels, params) inputs, targets = torch.tensor(p_test_data).float(), torch.tensor( p_test_labels).float() fig = plt.figure(figsize=(15, 10)) gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 2]) ax1 = plt.subplot(gs[0]) ax2 = plt.subplot(gs[1]) ax3 = plt.subplot(gs[2]) #A, B PREDICTION/LABEL GRAPHS predictions = net(inputs).detach().numpy().reshape(len(targets), 2) x1, y1 = [l[0] for l in targets], [l[1] for l in targets] x2, y2 = [l[0] for l in predictions], [l[1] for l in predictions]
print("Net ready, creating training set") epochs = 5000 train_size = 5000 val_size = 50 #VALEURS params = get_params() arange, brange, pop, n, T = params #TRAINING SET train_data, train_labels = gen_data( arange, brange, pop, n, T, train_size) #data,labels = infected curve(array), (a,b) p_train_data, p_train_labels = preprocessing( train_data, train_labels, params ) #p_data, p_labels = preprocesed data/labels : (max,max position,max delta,average) and normalized a and b train_inputs, train_targets = torch.tensor(p_train_data).float(), torch.tensor( p_train_labels).float( ) #inputs, labels = pytroch tensors for p_data and p_labels print("Train set ready") #VALIDATION SET val_data, val_labels = gen_data(arange, brange, pop, n, T, val_size) p_val_data, p_val_labels = preprocessing(val_data, val_labels, params) val_inputs, val_targets = torch.tensor(p_val_data).float(), torch.tensor( p_val_labels).float() print("Validation set ready.") criterion = torch.nn.MSELoss() #Loss function
def test_lowercase(self): self.assertEqual(fs.preprocessing('HorSe.'), 'horse .') self.assertEqual( fs.preprocessing('This is a Test. UPPER CASE should not Exist.'), 'this is a test . upper case should not exist .')
def test_multiple_spaces(self): self.assertEqual( fs.preprocessing('Multiple spaces should disappear!'), 'multiple spaces should disappear !')
def test_space_before_punctuation(self): self.assertEqual( fs.preprocessing(''' Sometimes Phrases are not finished with period And got loose'''), 'sometimes . phrases are not finished with period . and got loose')
def test_possessive(self): self.assertEqual(fs.preprocessing("This is Joe's book"), 'this is joe book')
def test_single_quotes(self): self.assertEqual( fs.preprocessing("This is an article with 'single' 'quotes'"), 'this is an article with single quotes')
def test_double_quotes(self): self.assertEqual( fs.preprocessing('This is an article with "double" "quotes"'), 'this is an article with double quotes')
def test_brackets(self): self.assertEqual( fs.preprocessing('This is an article with [text in brackets]'), 'this is an article with text in brackets')
def test_paranthesis(self): self.assertEqual( fs.preprocessing('This is an article with (text in parenthesis)'), 'this is an article with text in parenthesis')
def test_acronym(self): self.assertEqual(fs.preprocessing('u.s.a.'), 'usa')
server = app.server colors = {'background': '#250000', 'text': 'white'} # Para usar en el Output de los callbacks sigxsec = [f"{r['sigla']}-{r['sec']}" for r in ramos] n_rows = len(ramos) // 2 if len(ramos) % 2 == 0 else len(ramos) // 2 + 1 rows = [[] for _ in range(n_rows)] for ramo in ramos: for row in rows: if len(row) < 2: pass else: continue nrc, sigla, sec = ramo.values() data, name_ = vacantes(semestre, nrc, sigla, sec) df = preprocessing(data) fig = px.sunburst( data_frame=df, path=['T_Vacante', 'Escuela'], values='Vacantes', color='T_Vacante', color_discrete_map={ 'Disponible': 'Lavender', 'Ocupado': 'Firebrick' }, ) fig.update_layout( margin=dict(t=30, b=30), plot_bgcolor=colors['background'], paper_bgcolor=colors['background'],