Amirizaniani commited on
Commit
07f2e3e
1 Parent(s): 5e953eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -12
app.py CHANGED
@@ -45,10 +45,37 @@ def updateChoices(prompt):
45
  newChoices = generate_prompts(prompt)
46
  return gr.CheckboxGroup(choices=newChoices)
47
 
48
- def setTextVisibility(cbg):
49
- update_show = [gr.Textbox(visible=True, label=text, value=answer_question(text)) for text in cbg]
50
- update_hide = [gr.Textbox(visible=False, label="") for _ in range(10-len(cbg))]
51
- return update_show + update_hide
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
54
 
@@ -74,25 +101,36 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
74
  </div>
75
  """)
76
 
 
 
77
  with gr.Row():
78
  prompt_input = gr.Textbox(label="Enter your question", placeholder="Enter Your Question")
79
  with gr.Row():
80
- generate_button = gr.Button("Generate")
81
  with gr.Column():
82
  cbg = gr.CheckboxGroup(choices=[], label="List of the prompts", interactive=True)
83
 
84
  generate_button.click(updateChoices, inputs=[prompt_input], outputs=[cbg])
85
-
86
- with gr.Row(variant="compact") as exec:
87
- btnExec = gr.Button("Execute")
 
 
88
  with gr.Column() as texts:
89
  for i in range(10):
90
  text = gr.Textbox(label="_", visible=False)
91
  text_list.append(text)
92
-
93
- btnExec.click(setTextVisibility, inputs=cbg, outputs=text_list)
94
-
95
- Clear = gr.ClearButton([prompt_input, cbg, text], scale=1)
 
 
 
 
 
 
 
96
 
97
  with gr.Tab("Batch Mode"):
98
  gr.HTML("""
 
45
  newChoices = generate_prompts(prompt)
46
  return gr.CheckboxGroup(choices=newChoices)
47
 
48
+ def setTextVisibility(cbg, model_name_input):
49
+ sentences = []
50
+ result = []
51
+ model = SentenceTransformer('all-mpnet-base-v2')
52
+ exclude_words = {"a", "the", "for", "from", "of", "in", "over", "as", "on", "is", "am", "have", "an", "has", "had", "and", "by", "it", "its", "those", "these", "above", "to", "However"}
53
+ sentences_org = ["In a quaint little town nestled in the heart of the mountains, a small bakery famous for its artisanal breads and pastries had a line of customers stretching out the door, eagerly waiting to savor the freshly baked goods that were known far and wide for their delightful flavors.",
54
+ "Within a picturesque mountain village, there stood a renowned bakery, celebrated for its handcrafted bread and sweet treats, attracting a long queue of patrons each morning, all keen to enjoy the baked delicacies that had gained widespread acclaim for their exceptional taste.",
55
+ "A charming bakery, located in a small mountainous hamlet, renowned for producing exquisite handmade pastries and bread, was bustling with a crowd of eager customers lined up outside, each anticipating the chance to indulge in the famous baked items celebrated for their extraordinary deliciousness.",
56
+ "In a cozy, mountain-encircled village, a beloved bakery was the center of attraction, known for its traditional baking methods and delightful pastries, drawing a consistent stream of people waiting outside, all desiring to experience the renowned flavors that made the bakery's products distinctively mouth-watering."]
57
+ for text in cbg:
58
+ sentences.append(answer_question(text, model_name_input))
59
+
60
+ highlighted_sentences = []
61
+ for i, sentence in enumerate(sentences):
62
+ other_sentences = sentences[:i] + sentences[i+1:]
63
+ highlighted_sentence = highlight_words(sentence, other_sentences, model, exclude_words)
64
+ highlighted_sentences.append(highlighted_sentence)
65
+
66
+ for idx, sentence in enumerate(highlighted_sentences):
67
+ result.append("<p><strong>"+ cbg[idx] +"</strong></p><p>"+ sentence +"</p><br/>")
68
+
69
+ score = round(calculate_similarity_score(sentences))
70
+
71
+ final_html = f"""<div>{result}<div style="text-align: center; font-size: 24px; font-weight: bold;">Similarity Score: {score}</div></div>"""
72
+
73
+
74
+ return final_html
75
+
76
+ def upload_file(files):
77
+ file_paths = [file.name for file in files]
78
+ return file_paths
79
 
80
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
81
 
 
101
  </div>
102
  """)
103
 
104
+ with gr.Row():
105
+ model_name_input = gr.Dropdown([("Llama", "TheBloke/Llama-2-7B-Chat-GGML"), ("Falcon", "TheBloke/Falcon-180B-GGUF"), ("Zephyr", "TheBloke/zephyr-quiklang-3b-4K-GGUF"),("Vicuna", "TheBloke/vicuna-33B-GGUF"),("Claude","TheBloke/claude2-alpaca-13B-GGUF"),("Alpaca","TheBloke/LeoScorpius-GreenNode-Alpaca-7B-v1-GGUF")], label="Large Language Model")
106
  with gr.Row():
107
  prompt_input = gr.Textbox(label="Enter your question", placeholder="Enter Your Question")
108
  with gr.Row():
109
+ generate_button = gr.Button("Generate", variant="primary", min_width=300)
110
  with gr.Column():
111
  cbg = gr.CheckboxGroup(choices=[], label="List of the prompts", interactive=True)
112
 
113
  generate_button.click(updateChoices, inputs=[prompt_input], outputs=[cbg])
114
+
115
+ with gr.Row() as exec:
116
+ btnExec = gr.Button("Execute", variant="primary", min_width=200)
117
+
118
+
119
  with gr.Column() as texts:
120
  for i in range(10):
121
  text = gr.Textbox(label="_", visible=False)
122
  text_list.append(text)
123
+
124
+ with gr.Column():
125
+ html_result = gr.HTML("""<div style="color: red"></div>""")
126
+
127
+ #btnExec.click(setTextVisibility, inputs=[cbg, model_name_input], outputs=text_list)
128
+ btnExec.click(setTextVisibility, inputs=[cbg, model_name_input], outputs=html_result)
129
+ gr.HTML("""
130
+ <div style="text-align: center; font-size: 24px; font-weight: bold;">Similarity Score:</div>
131
+ """)
132
+
133
+ clear = gr.ClearButton(link = "http://127.0.0.1:7860")
134
 
135
  with gr.Tab("Batch Mode"):
136
  gr.HTML("""