Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -163,7 +163,29 @@ def switch_content(choice):
|
|
| 163 |
return HF_REFERENCE_HTML
|
| 164 |
|
| 165 |
|
| 166 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|