enochlev commited on
Commit
4458580
·
1 Parent(s): c01db2b
Files changed (1) hide show
  1. app.py +50 -4
app.py CHANGED
@@ -1,7 +1,53 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import time
3
+ from sentence_transformers import CrossEncoder
4
 
5
+ # Load model
6
+ model2 = CrossEncoder('enochlev/coherence-all-mpnet-base-v2')
7
 
8
+ # Predefined examples
9
+ examples = [
10
+ ["What is your favorite color?", "Blue!"],
11
+ ["Do you like playing outside?", "I like ice cream."],
12
+ ["What is your favorite animal?", "I like dogs!"],
13
+ ["Do you want to go to the park?", "Yes, I want to go on the swings!"],
14
+ ["What is your favorite food?", "I like playing with blocks."],
15
+ ["Do you have a pet?", "Yes, I have a cat named Whiskers."],
16
+ ["What is your favorite thing to do on a sunny day?", "I like playing soccer with my friends."]
17
+ ]
18
+
19
+ # Global index for cycling through examples
20
+ current_index = 0
21
+
22
+ def check_coherence(sentence1: str, sentence2: str) -> float:
23
+ """
24
+ Predicts the coherence score for a pair of sentences.
25
+ """
26
+ score = model2.predict([[sentence1, sentence2]])[0]
27
+ return score
28
+
29
+ def get_next_example():
30
+ """
31
+ Returns the next example pair and updates the current index.
32
+ """
33
+ global current_index
34
+ pair = examples[current_index]
35
+ current_index = (current_index + 1) % len(examples)
36
+ return pair[0], pair[1]
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("## Coherence Checker Demo")
40
+
41
+ with gr.Row():
42
+ with gr.Column():
43
+ inp1 = gr.Textbox(label="Sentence 1", placeholder="Enter first sentence...")
44
+ inp2 = gr.Textbox(label="Sentence 2", placeholder="Enter second sentence...")
45
+ check_button = gr.Button("Check Coherence")
46
+ next_example_button = gr.Button("Next Example")
47
+ with gr.Column():
48
+ output_score = gr.Textbox(label="Coherence Score", interactive=False)
49
+
50
+ check_button.click(fn=check_coherence, inputs=[inp1, inp2], outputs=output_score)
51
+ next_example_button.click(fn=get_next_example, inputs=[], outputs=[inp1, inp2])
52
+
53
+ demo.launch()