Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,8 @@ import gradio as gr
|
|
33 |
from tree import generate_plot
|
34 |
from paraphraser import generate_paraphrase
|
35 |
from lcs import find_common_subsequences
|
36 |
-
from highlighter import highlight_common_words
|
|
|
37 |
|
38 |
nltk.download('stopwords')
|
39 |
|
@@ -42,12 +43,14 @@ nltk.download('stopwords')
|
|
42 |
def model(prompt):
|
43 |
sentence = prompt
|
44 |
paraphrased_sentences = generate_paraphrase(sentence)
|
45 |
-
|
|
|
46 |
highlighted_user_prompt = highlight_common_words(common_grams, [sentence], "User Prompt (Highlighted and Numbered)") # Pass the sentence as a list
|
47 |
-
highlighted_paraphrased_sentences =
|
48 |
-
|
|
|
49 |
tree = generate_plot(sentence)
|
50 |
-
return highlighted_user_prompt,
|
51 |
|
52 |
|
53 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
@@ -61,20 +64,20 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
61 |
clear_button = gr.Button("Clear")
|
62 |
|
63 |
with gr.Row():
|
64 |
-
|
65 |
|
66 |
with gr.Row():
|
67 |
-
|
68 |
|
69 |
with gr.Row():
|
70 |
-
|
71 |
|
72 |
with gr.Row():
|
73 |
tree = gr.Plot()
|
74 |
|
75 |
-
submit_button.click(model, inputs=user_input, outputs=[
|
76 |
clear_button.click(lambda: "", inputs=None, outputs=user_input)
|
77 |
-
clear_button.click(lambda: "", inputs=None, outputs=[
|
78 |
|
79 |
# Launch the demo
|
80 |
demo.launch(share=True)
|
|
|
33 |
from tree import generate_plot
|
34 |
from paraphraser import generate_paraphrase
|
35 |
from lcs import find_common_subsequences
|
36 |
+
from highlighter import highlight_common_words, highlight_common_words_dict
|
37 |
+
from entailment import analyze_entailment
|
38 |
|
39 |
nltk.download('stopwords')
|
40 |
|
|
|
43 |
def model(prompt):
|
44 |
sentence = prompt
|
45 |
paraphrased_sentences = generate_paraphrase(sentence)
|
46 |
+
analyzed_paraphrased_sentences, selected_sentences, discarded_sentences = analyze_entailment(sentence, paraphrased_sentences, 0.7)
|
47 |
+
common_grams = find_common_subsequences(sentence, selected_sentences)
|
48 |
highlighted_user_prompt = highlight_common_words(common_grams, [sentence], "User Prompt (Highlighted and Numbered)") # Pass the sentence as a list
|
49 |
+
# highlighted_paraphrased_sentences = highlight_common_words_dict(common_grams, analyzed_paraphrased_sentences, "Paraphrased Sentences") # Fix parameter order
|
50 |
+
highlighted_selected_sentences = highlight_common_words_dict(common_grams, selected_sentences, "Selected Sentences from the Paraphrased Sentences", "#C1E1C1")
|
51 |
+
highlighted_discarded_sentences = highlight_common_words_dict(common_grams, discarded_sentences, "Discarded Sentences from the Paraphrased Sentences", "#FDE0E0")
|
52 |
tree = generate_plot(sentence)
|
53 |
+
return highlighted_user_prompt, highlighted_selected_sentences, highlighted_discarded_sentences, tree
|
54 |
|
55 |
|
56 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
|
64 |
clear_button = gr.Button("Clear")
|
65 |
|
66 |
with gr.Row():
|
67 |
+
highlighted_user_prompt = gr.HTML()
|
68 |
|
69 |
with gr.Row():
|
70 |
+
highlighted_selected_sentences = gr.HTML()
|
71 |
|
72 |
with gr.Row():
|
73 |
+
highlighted_discarded_sentences = gr.HTML()
|
74 |
|
75 |
with gr.Row():
|
76 |
tree = gr.Plot()
|
77 |
|
78 |
+
submit_button.click(model, inputs=user_input, outputs=[highlighted_user_prompt, highlighted_selected_sentences, highlighted_discarded_sentences, tree])
|
79 |
clear_button.click(lambda: "", inputs=None, outputs=user_input)
|
80 |
+
clear_button.click(lambda: "", inputs=None, outputs=[highlighted_user_prompt, highlighted_selected_sentences, highlighted_discarded_sentences, tree])
|
81 |
|
82 |
# Launch the demo
|
83 |
demo.launch(share=True)
|