Commit ·
eb21a74
1
Parent(s): 1cd86f2
clear button, and user enhancements
Browse files
app.py
CHANGED
|
@@ -25,12 +25,22 @@ try:
|
|
| 25 |
|
| 26 |
except Exception as e:
|
| 27 |
def show_error(*args):
|
| 28 |
-
return f"// ERROR: Failed to load core agent code. Details: {e}", "",
|
| 29 |
|
| 30 |
# --- Gradio UI setup below ---
|
| 31 |
with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) as demo:
|
| 32 |
gr.Markdown("## DeepV for RTL Code Generation — Model-Agnostic (Bring Your Own API Key)")
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
with gr.Row():
|
| 35 |
with gr.Column(scale=2):
|
| 36 |
with gr.Row():
|
|
@@ -46,22 +56,29 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) a
|
|
| 46 |
**Note:** Your API key is used for the current session only and is not saved or stored.
|
| 47 |
"""
|
| 48 |
)
|
| 49 |
-
|
| 50 |
spec = gr.Textbox(
|
| 51 |
label="Design Specification (natural language or I/O contract)",
|
| 52 |
placeholder="e.g., 8-bit UART transmitter with baud rate generator ...",
|
| 53 |
-
lines=10
|
|
|
|
| 54 |
)
|
| 55 |
with gr.Row():
|
| 56 |
use_rag = gr.Checkbox(value=True, label="Use Retrieval (RAG)")
|
| 57 |
top_k = gr.Slider(1, 10, value=3, step=1, label="Top-K retrieved examples")
|
| 58 |
-
|
| 59 |
with gr.Accordion("Generation Settings", open=False):
|
| 60 |
temperature = gr.Slider(0.0, 1.5, value=0.2, step=0.05, label="Temperature")
|
| 61 |
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
| 62 |
max_new_tokens = gr.Slider(128, 4096, value=768, step=64, label="Max tokens")
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
with gr.Column(scale=3):
|
| 66 |
gr.Markdown("**Output**")
|
| 67 |
with gr.Group():
|
|
@@ -82,7 +99,7 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) a
|
|
| 82 |
)
|
| 83 |
with gr.Tab("Preview of Retrieved Context (raw)"):
|
| 84 |
retrieved_raw = gr.HighlightedText(label="(first K documents)", combine_adjacent=True)
|
| 85 |
-
|
| 86 |
# --- Back-end copy function ---
|
| 87 |
def copy_to_clipboard_fn(text):
|
| 88 |
return text
|
|
@@ -90,8 +107,23 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) a
|
|
| 90 |
run_btn.click(
|
| 91 |
fn=run_generation,
|
| 92 |
inputs=[spec, use_rag, top_k, model_choice, api_key, temperature, top_p, max_new_tokens],
|
| 93 |
-
outputs=[out_code, retrieved_list, retrieved_raw]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
copy_button.click(
|
| 97 |
fn=copy_to_clipboard_fn,
|
|
@@ -116,8 +148,8 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) a
|
|
| 116 |
|
| 117 |
#copy-button {
|
| 118 |
position: absolute;
|
| 119 |
-
top:
|
| 120 |
-
right:
|
| 121 |
z-index: 10;
|
| 122 |
}
|
| 123 |
"""
|
|
|
|
| 25 |
|
| 26 |
except Exception as e:
|
| 27 |
def show_error(*args):
|
| 28 |
+
return f"// ERROR: Failed to load core agent code. Details: {e}", "", ""
|
| 29 |
|
| 30 |
# --- Gradio UI setup below ---
|
| 31 |
with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) as demo:
|
| 32 |
gr.Markdown("## DeepV for RTL Code Generation — Model-Agnostic (Bring Your Own API Key)")
|
| 33 |
|
| 34 |
+
# Status Bar for success/error messages
|
| 35 |
+
status_bar = gr.Textbox(
|
| 36 |
+
label="Status",
|
| 37 |
+
lines=1,
|
| 38 |
+
interactive=False,
|
| 39 |
+
show_copy_button=False,
|
| 40 |
+
container=False,
|
| 41 |
+
value="Ready"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
with gr.Row():
|
| 45 |
with gr.Column(scale=2):
|
| 46 |
with gr.Row():
|
|
|
|
| 56 |
**Note:** Your API key is used for the current session only and is not saved or stored.
|
| 57 |
"""
|
| 58 |
)
|
| 59 |
+
|
| 60 |
spec = gr.Textbox(
|
| 61 |
label="Design Specification (natural language or I/O contract)",
|
| 62 |
placeholder="e.g., 8-bit UART transmitter with baud rate generator ...",
|
| 63 |
+
lines=10,
|
| 64 |
+
elem_id="spec-input"
|
| 65 |
)
|
| 66 |
with gr.Row():
|
| 67 |
use_rag = gr.Checkbox(value=True, label="Use Retrieval (RAG)")
|
| 68 |
top_k = gr.Slider(1, 10, value=3, step=1, label="Top-K retrieved examples")
|
| 69 |
+
|
| 70 |
with gr.Accordion("Generation Settings", open=False):
|
| 71 |
temperature = gr.Slider(0.0, 1.5, value=0.2, step=0.05, label="Temperature")
|
| 72 |
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
| 73 |
max_new_tokens = gr.Slider(128, 4096, value=768, step=64, label="Max tokens")
|
| 74 |
|
| 75 |
+
with gr.Row():
|
| 76 |
+
run_btn = gr.Button("Generate Verilog", variant="primary")
|
| 77 |
+
clear_btn = gr.ClearButton(
|
| 78 |
+
value="Clear All",
|
| 79 |
+
components=[spec, api_key, out_code, retrieved_list, retrieved_raw]
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
with gr.Column(scale=3):
|
| 83 |
gr.Markdown("**Output**")
|
| 84 |
with gr.Group():
|
|
|
|
| 99 |
)
|
| 100 |
with gr.Tab("Preview of Retrieved Context (raw)"):
|
| 101 |
retrieved_raw = gr.HighlightedText(label="(first K documents)", combine_adjacent=True)
|
| 102 |
+
|
| 103 |
# --- Back-end copy function ---
|
| 104 |
def copy_to_clipboard_fn(text):
|
| 105 |
return text
|
|
|
|
| 107 |
run_btn.click(
|
| 108 |
fn=run_generation,
|
| 109 |
inputs=[spec, use_rag, top_k, model_choice, api_key, temperature, top_p, max_new_tokens],
|
| 110 |
+
outputs=[out_code, retrieved_list, retrieved_raw],
|
| 111 |
+
# Show a progress spinner and status bar update during execution
|
| 112 |
+
show_progress=True
|
| 113 |
+
).then(
|
| 114 |
+
fn=lambda: gr.update(value="Success!"),
|
| 115 |
+
outputs=[status_bar]
|
| 116 |
+
).success(
|
| 117 |
+
fn=lambda: gr.update(value="Success!"),
|
| 118 |
+
outputs=[status_bar]
|
| 119 |
+
).exc(
|
| 120 |
+
fn=lambda: gr.update(value="Generation Failed. Check error message.",),
|
| 121 |
+
outputs=[status_bar]
|
| 122 |
)
|
| 123 |
+
|
| 124 |
+
# Update the status bar on other events
|
| 125 |
+
clear_btn.click(fn=lambda: gr.update(value="Ready"), outputs=[status_bar])
|
| 126 |
+
spec.change(fn=lambda: gr.update(value="Ready"), outputs=[status_bar])
|
| 127 |
|
| 128 |
copy_button.click(
|
| 129 |
fn=copy_to_clipboard_fn,
|
|
|
|
| 148 |
|
| 149 |
#copy-button {
|
| 150 |
position: absolute;
|
| 151 |
+
top: 20px;
|
| 152 |
+
right: 10px;
|
| 153 |
z-index: 10;
|
| 154 |
}
|
| 155 |
"""
|