Update app.py
Browse files
app.py
CHANGED
|
@@ -86,22 +86,13 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
|
|
| 86 |
with gr.Column(scale=3):
|
| 87 |
gr.Markdown("**Output**")
|
| 88 |
out_code = gr.Textbox(
|
| 89 |
-
label="Generated Verilog
|
| 90 |
lines=28,
|
| 91 |
interactive=False,
|
| 92 |
-
placeholder="// Your Verilog code will appear here"
|
| 93 |
-
# This small JavaScript snippet is added directly to the Textbox.
|
| 94 |
-
# When a user clicks, it selects all the text, making it easy to copy.
|
| 95 |
-
elem_js="""
|
| 96 |
-
(el) => {
|
| 97 |
-
el.addEventListener('click', () => {
|
| 98 |
-
if (el.setSelectionRange) {
|
| 99 |
-
el.setSelectionRange(0, el.value.length);
|
| 100 |
-
}
|
| 101 |
-
});
|
| 102 |
-
}
|
| 103 |
-
"""
|
| 104 |
)
|
|
|
|
|
|
|
| 105 |
|
| 106 |
with gr.Tab("Retrieved Items (names + scores)"):
|
| 107 |
retrieved_list = gr.Textbox(
|
|
@@ -112,12 +103,37 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
|
|
| 112 |
with gr.Tab("Preview of Retrieved Context (raw)"):
|
| 113 |
retrieved_raw = gr.HighlightedText(label="(first K documents)", combine_adjacent=True)
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
run_btn.click(
|
| 116 |
fn=run_generation,
|
| 117 |
inputs=[spec, use_rag, top_k, model_choice, api_key, temperature, top_p, max_new_tokens],
|
| 118 |
outputs=[out_code, retrieved_list, retrieved_raw]
|
| 119 |
)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
if __name__ == "__main__":
|
| 122 |
if 'agent_module' in locals():
|
| 123 |
demo.launch()
|
|
|
|
| 86 |
with gr.Column(scale=3):
|
| 87 |
gr.Markdown("**Output**")
|
| 88 |
out_code = gr.Textbox(
|
| 89 |
+
label="Generated Verilog",
|
| 90 |
lines=28,
|
| 91 |
interactive=False,
|
| 92 |
+
placeholder="// Your Verilog code will appear here"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
)
|
| 94 |
+
# Add a dedicated copy button
|
| 95 |
+
copy_button = gr.Button("Copy Code", variant="secondary")
|
| 96 |
|
| 97 |
with gr.Tab("Retrieved Items (names + scores)"):
|
| 98 |
retrieved_list = gr.Textbox(
|
|
|
|
| 103 |
with gr.Tab("Preview of Retrieved Context (raw)"):
|
| 104 |
retrieved_raw = gr.HighlightedText(label="(first K documents)", combine_adjacent=True)
|
| 105 |
|
| 106 |
+
# --- Back-end copy function ---
|
| 107 |
+
def copy_to_clipboard_fn(text):
|
| 108 |
+
# This function simply returns the text passed to it.
|
| 109 |
+
# This is a safe way to trigger the JS event on the client side
|
| 110 |
+
return text
|
| 111 |
+
|
| 112 |
run_btn.click(
|
| 113 |
fn=run_generation,
|
| 114 |
inputs=[spec, use_rag, top_k, model_choice, api_key, temperature, top_p, max_new_tokens],
|
| 115 |
outputs=[out_code, retrieved_list, retrieved_raw]
|
| 116 |
)
|
| 117 |
|
| 118 |
+
# This is the key change. We use the most basic form of a click event,
|
| 119 |
+
# which is guaranteed to work even on older Gradio versions.
|
| 120 |
+
copy_button.click(
|
| 121 |
+
fn=copy_to_clipboard_fn,
|
| 122 |
+
inputs=[out_code],
|
| 123 |
+
outputs=[],
|
| 124 |
+
js="""
|
| 125 |
+
(text) => {
|
| 126 |
+
const el = document.createElement('textarea');
|
| 127 |
+
el.value = text;
|
| 128 |
+
document.body.appendChild(el);
|
| 129 |
+
el.select();
|
| 130 |
+
document.execCommand('copy');
|
| 131 |
+
document.body.removeChild(el);
|
| 132 |
+
}
|
| 133 |
+
"""
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
if __name__ == "__main__":
|
| 138 |
if 'agent_module' in locals():
|
| 139 |
demo.launch()
|