CesarLeblanc commited on
Commit
f2c857b
1 Parent(s): 3c63477

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -86,17 +86,20 @@ def masking(text):
86
  max_score = 0
87
  best_prediction = None
88
  best_position = None
 
89
 
90
  # Case for the first position
91
  masked_text = "[MASK], " + ', '.join(text.split(', '))
92
  prediction = mask_model(masked_text)[0]
93
  species = prediction['token_str']
94
  score = prediction['score']
 
95
 
96
  if score > max_score:
97
  max_score = score
98
  best_prediction = species
99
  best_position = 0
 
100
 
101
  # Loop through each position in the middle of the sentence
102
  for i in range(1, len(text.split(', '))):
@@ -104,25 +107,29 @@ def masking(text):
104
  prediction = mask_model(masked_text)[0]
105
  species = prediction['token_str']
106
  score = prediction['score']
 
107
 
108
  # Update best prediction and position if score is higher
109
  if score > max_score:
110
  max_score = score
111
  best_prediction = species
112
  best_position = i
 
113
 
114
  # Case for the last position
115
  masked_text = ', '.join(text.split(', ')) + ', [MASK]'
116
  prediction = mask_model(masked_text)[0]
117
  species = prediction['token_str']
118
  score = prediction['score']
 
119
 
120
  if score > max_score:
121
  max_score = score
122
  best_prediction = species
123
  best_position = len(text.split(', '))
 
124
 
125
- text = f"The most likely missing species in position {best_position} is: {best_prediction}."
126
  image = return_species_image(best_prediction)
127
  return text, image
128
 
 
86
  max_score = 0
87
  best_prediction = None
88
  best_position = None
89
+ best_sentence = None
90
 
91
  # Case for the first position
92
  masked_text = "[MASK], " + ', '.join(text.split(', '))
93
  prediction = mask_model(masked_text)[0]
94
  species = prediction['token_str']
95
  score = prediction['score']
96
+ sentence = prediction['sequence']
97
 
98
  if score > max_score:
99
  max_score = score
100
  best_prediction = species
101
  best_position = 0
102
+ best_sentence = sentence
103
 
104
  # Loop through each position in the middle of the sentence
105
  for i in range(1, len(text.split(', '))):
 
107
  prediction = mask_model(masked_text)[0]
108
  species = prediction['token_str']
109
  score = prediction['score']
110
+ sentence = prediction['sequence']
111
 
112
  # Update best prediction and position if score is higher
113
  if score > max_score:
114
  max_score = score
115
  best_prediction = species
116
  best_position = i
117
+ best_sentence = sentence
118
 
119
  # Case for the last position
120
  masked_text = ', '.join(text.split(', ')) + ', [MASK]'
121
  prediction = mask_model(masked_text)[0]
122
  species = prediction['token_str']
123
  score = prediction['score']
124
+ sentence = prediction['sequence']
125
 
126
  if score > max_score:
127
  max_score = score
128
  best_prediction = species
129
  best_position = len(text.split(', '))
130
+ best_sentence = sentence
131
 
132
+ text = f"The most likely missing species is {best_prediction} at position {best_position}.\nThe new vegetation plot is {best_sentence}."
133
  image = return_species_image(best_prediction)
134
  return text, image
135