Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,6 +55,50 @@ if torch.cuda.is_available():
|
|
| 55 |
else:
|
| 56 |
power_device = "CPU"
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
with gr.Blocks(css=css) as demo:
|
| 59 |
|
| 60 |
with gr.Column(elem_id="col-container"):
|
|
@@ -62,6 +106,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 62 |
# Text-to-Image Gradio Template
|
| 63 |
Currently running on {power_device}.
|
| 64 |
""")
|
|
|
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
|
|
@@ -142,5 +187,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 142 |
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
| 143 |
outputs = [result]
|
| 144 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
demo.queue().launch()
|
|
|
|
| 55 |
else:
|
| 56 |
power_device = "CPU"
|
| 57 |
|
| 58 |
+
html_content = """
|
| 59 |
+
<p id="sourceText" style="width: 400px; padding: 10px; border: 1px solid #000;" onmouseup="selectText()">
|
| 60 |
+
这是一个可拖动文本的示例。选择这段话中的部分文字并拖动到下方的文本框中作为标签。
|
| 61 |
+
</p>
|
| 62 |
+
<div id="dropzone" ondrop="drop(event)" ondragover="allowDrop(event)" style="width: 400px; height: 200px; border: 1px solid #000; margin-top: 20px;">
|
| 63 |
+
将选中的文字拖动到这里
|
| 64 |
+
</div>
|
| 65 |
+
<script>
|
| 66 |
+
let selectedText = '';
|
| 67 |
+
|
| 68 |
+
function selectText() {
|
| 69 |
+
const selection = window.getSelection();
|
| 70 |
+
selectedText = selection.toString();
|
| 71 |
+
if (selectedText) {
|
| 72 |
+
const span = document.createElement('span');
|
| 73 |
+
span.textContent = selectedText;
|
| 74 |
+
span.setAttribute('draggable', true);
|
| 75 |
+
span.setAttribute('ondragstart', 'drag(event)');
|
| 76 |
+
selection.removeAllRanges();
|
| 77 |
+
selection.anchorNode.parentElement.insertBefore(span, selection.anchorNode.nextSibling);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function allowDrop(event) {
|
| 82 |
+
event.preventDefault();
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function drag(event) {
|
| 86 |
+
event.dataTransfer.setData("text/plain", event.target.textContent);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
function drop(event) {
|
| 90 |
+
event.preventDefault();
|
| 91 |
+
const data = event.dataTransfer.getData("text/plain");
|
| 92 |
+
const tag = document.createElement('div');
|
| 93 |
+
tag.textContent = data;
|
| 94 |
+
tag.style.border = '1px solid #000';
|
| 95 |
+
tag.style.padding = '5px';
|
| 96 |
+
tag.style.margin = '5px';
|
| 97 |
+
event.target.appendChild(tag);
|
| 98 |
+
}
|
| 99 |
+
</script>
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
with gr.Blocks(css=css) as demo:
|
| 103 |
|
| 104 |
with gr.Column(elem_id="col-container"):
|
|
|
|
| 106 |
# Text-to-Image Gradio Template
|
| 107 |
Currently running on {power_device}.
|
| 108 |
""")
|
| 109 |
+
gr.HTML(html_content)
|
| 110 |
|
| 111 |
with gr.Row():
|
| 112 |
|
|
|
|
| 187 |
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
| 188 |
outputs = [result]
|
| 189 |
)
|
| 190 |
+
# 自定义HTML和JavaScript
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
|
| 195 |
demo.queue().launch()
|