jgrosjean commited on
Commit
f98ea7f
1 Parent(s): 77dfeae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -24
app.py CHANGED
@@ -27,12 +27,7 @@ def generate_sentence_embedding(sentence, language):
27
  embedding = sum_embeddings / sum_mask
28
  return embedding
29
 
30
- def calculate_cosine_similarities(row_source_sentence, source_language, row_target_sentence_1, target_language_1, row_target_sentence_2, target_language_2, row_target_sentence_3, target_language_3):
31
- source_sentence = row_source_sentence[0]
32
- target_sentence_1 = row_target_sentence_1[0]
33
- target_sentence_2 = row_target_sentence_2[0]
34
- target_sentence_3 = row_target_sentence_3[0]
35
-
36
  source_embedding = generate_sentence_embedding(source_sentence, source_language)
37
  target_embedding_1 = generate_sentence_embedding(target_sentence_1, target_language_1)
38
  target_embedding_2 = generate_sentence_embedding(target_sentence_2, target_language_2)
@@ -52,28 +47,19 @@ def calculate_cosine_similarities(row_source_sentence, source_language, row_targ
52
  cosine_scores_output = "**" + cosine_scores_output.replace("\n", "**\n", 1)
53
  return cosine_scores_output
54
 
55
-
56
  def main():
57
  demo = gr.Interface(
58
  fn=calculate_cosine_similarities,
59
  inputs=[
60
- gr.Row(
61
- gr.Textbox(lines=1, placeholder="Enter source sentence", label="Source Sentence"),
62
- gr.Dropdown(["de", "fr", "it", "rm"], label="Source Language")
63
- ),
64
- gr.Row(
65
- gr.Textbox(lines=1, placeholder="Enter target sentence 1", label="Target Sentence 1"),
66
- gr.Dropdown(["de", "fr", "it", "rm"], label="Target Language 1")
67
- ),
68
- gr.Row(
69
- gr.Textbox(lines=1, placeholder="Enter target sentence 2", label="Target Sentence 2"),
70
- gr.Dropdown(["de", "fr", "it", "rm"], label="Target Language 2")
71
- ),
72
- gr.Row(
73
- gr.Textbox(lines=1, placeholder="Enter target sentence 3", label="Target Sentence 3"),
74
- gr.Dropdown(["de", "fr", "it", "rm"], label="Target Language 3")
75
- )
76
- ],
77
  outputs= gr.Textbox(label="Cosine Similarity Scores", type="text", lines=3),
78
  title="Sentence Similarity Calculator",
79
  description="Enter a source sentence and up to three target sentences to calculate their cosine similarity.",
 
27
  embedding = sum_embeddings / sum_mask
28
  return embedding
29
 
30
+ def calculate_cosine_similarities(source_sentence, source_language, target_sentence_1, target_language_1, target_sentence_2, target_language_2, target_sentence_3, target_language_3):
 
 
 
 
 
31
  source_embedding = generate_sentence_embedding(source_sentence, source_language)
32
  target_embedding_1 = generate_sentence_embedding(target_sentence_1, target_language_1)
33
  target_embedding_2 = generate_sentence_embedding(target_sentence_2, target_language_2)
 
47
  cosine_scores_output = "**" + cosine_scores_output.replace("\n", "**\n", 1)
48
  return cosine_scores_output
49
 
 
50
  def main():
51
  demo = gr.Interface(
52
  fn=calculate_cosine_similarities,
53
  inputs=[
54
+ gr.Textbox(lines=1, placeholder="Enter source sentence", label="Source Sentence"),
55
+ gr.Dropdown(["de", "fr", "it", "rm"], label="Source Language"),
56
+ gr.Textbox(lines=1, placeholder="Enter target sentence 1", label="Target Sentence 1"),
57
+ gr.Dropdown(["de", "fr", "it", "rm"], label="Target Language 1"),
58
+ gr.Textbox(lines=1, placeholder="Enter target sentence 2", label="Target Sentence 2"),
59
+ gr.Dropdown(["de", "fr", "it", "rm"], label="Target Language 2"),
60
+ gr.Textbox(lines=1, placeholder="Enter target sentence 3", label="Target Sentence 3"),
61
+ gr.Dropdown(["de", "fr", "it", "rm"], label="Target Language 3")
62
+ ],
 
 
 
 
 
 
 
 
63
  outputs= gr.Textbox(label="Cosine Similarity Scores", type="text", lines=3),
64
  title="Sentence Similarity Calculator",
65
  description="Enter a source sentence and up to three target sentences to calculate their cosine similarity.",