TheHickman commited on
Commit
fe5d643
·
verified ·
1 Parent(s): a5a4e31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -163,7 +163,29 @@ def switch_content(choice):
163
  return HF_REFERENCE_HTML
164
 
165
 
166
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  gr.Markdown("### 📘 Highlight text and ask GPT for help")
168
 
169
  view_toggle = gr.Radio(
 
163
  return HF_REFERENCE_HTML
164
 
165
 
166
+ with gr.Blocks(
167
+ head="""
168
+ <script>
169
+ document.addEventListener("mouseup", function () {
170
+ const selection = window.getSelection().toString().trim();
171
+ if (selection.length > 0) {
172
+ const textboxContainer = document.querySelector('[aria-label="Selected text"]');
173
+ if (textboxContainer) {
174
+ const textarea = textboxContainer.querySelector("textarea");
175
+ if (textarea) {
176
+ const nativeSetter = Object.getOwnPropertyDescriptor(
177
+ window.HTMLTextAreaElement.prototype,
178
+ "value"
179
+ ).set;
180
+ nativeSetter.call(textarea, selection);
181
+ textarea.dispatchEvent(new Event("input", { bubbles: true }));
182
+ }
183
+ }
184
+ }
185
+ });
186
+ </script>
187
+ """
188
+ ) as demo:
189
  gr.Markdown("### 📘 Highlight text and ask GPT for help")
190
 
191
  view_toggle = gr.Radio(