Spaces:
Sleeping
Sleeping
style: update UI module style to latest version and add code input
Browse files- app.py +1 -1
- ui_module.py +112 -81
app.py
CHANGED
|
@@ -258,4 +258,4 @@ def generate_response(prompt: str) -> str:
|
|
| 258 |
app = build_ui(validate_and_evaluate)
|
| 259 |
|
| 260 |
# Launch the web application
|
| 261 |
-
app.launch()
|
|
|
|
| 258 |
app = build_ui(validate_and_evaluate)
|
| 259 |
|
| 260 |
# Launch the web application
|
| 261 |
+
app.launch(css=CUSTOM_CSS)
|
ui_module.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
# ---------------------------------------------------------------------------
|
| 5 |
# MODULE 1 — UI Module
|
| 6 |
# ---------------------------------------------------------------------------
|
|
|
|
| 7 |
CUSTOM_CSS = """
|
| 8 |
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');
|
| 9 |
*, *::before, *::after { box-sizing: border-box; }
|
|
@@ -40,6 +41,11 @@ body, .gradio-container {
|
|
| 40 |
color: #E8EAF0 !important;
|
| 41 |
margin: 0 !important;
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
.eval-header .model-badge {
|
| 44 |
margin-left: auto;
|
| 45 |
font-family: 'Space Mono', monospace;
|
|
@@ -75,10 +81,11 @@ body, .gradio-container {
|
|
| 75 |
.gradio-textbox textarea::placeholder {
|
| 76 |
color: #4A4E60 !important;
|
| 77 |
}
|
| 78 |
-
#code-input
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
}
|
| 83 |
.gradio-textbox label span,
|
| 84 |
.gradio-code label span {
|
|
@@ -102,8 +109,13 @@ body, .gradio-container {
|
|
| 102 |
transition: background 0.15s, transform 0.1s !important;
|
| 103 |
letter-spacing: -0.1px !important;
|
| 104 |
}
|
| 105 |
-
#eval-btn:hover {
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
#clear-btn {
|
| 108 |
background: transparent !important;
|
| 109 |
border: 1px solid #3A3E52 !important;
|
|
@@ -115,7 +127,10 @@ body, .gradio-container {
|
|
| 115 |
cursor: pointer !important;
|
| 116 |
transition: border-color 0.15s, color 0.15s !important;
|
| 117 |
}
|
| 118 |
-
#clear-btn:hover {
|
|
|
|
|
|
|
|
|
|
| 119 |
.results-heading {
|
| 120 |
font-size: 11px !important;
|
| 121 |
font-weight: 500 !important;
|
|
@@ -127,31 +142,51 @@ body, .gradio-container {
|
|
| 127 |
margin-bottom: 20px !important;
|
| 128 |
}
|
| 129 |
#verdict-out textarea {
|
| 130 |
-
background: #161820 !important;
|
| 131 |
-
border
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
#accuracy-out textarea {
|
| 137 |
-
background: #161820 !important;
|
| 138 |
-
border
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
}
|
| 143 |
#summary-out textarea {
|
| 144 |
-
background: #161820 !important;
|
| 145 |
-
border
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
#issues-out textarea {
|
| 150 |
-
background: #161820 !important;
|
| 151 |
-
border
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
}
|
| 156 |
#error-out textarea {
|
| 157 |
background: #1A0E0E !important;
|
|
@@ -162,22 +197,27 @@ body, .gradio-container {
|
|
| 162 |
padding: 14px 16px !important;
|
| 163 |
color: #F0997B !important;
|
| 164 |
cursor: default !important;
|
| 165 |
-
min-height: 120px !important;
|
| 166 |
-
width: 100% !important;
|
| 167 |
}
|
| 168 |
-
.divider {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
footer { display: none !important; }
|
| 170 |
-
|
| 171 |
-
::-webkit-scrollbar
|
| 172 |
-
::-webkit-scrollbar-
|
|
|
|
| 173 |
::-webkit-scrollbar-thumb:hover { background: #534AB7; }
|
| 174 |
"""
|
| 175 |
|
| 176 |
HEADER_HTML = """
|
| 177 |
<div class="eval-header">
|
| 178 |
<div class="logo">🔍</div>
|
| 179 |
-
<div>
|
| 180 |
-
|
|
|
|
|
|
|
| 181 |
</div>
|
| 182 |
"""
|
| 183 |
|
|
@@ -188,11 +228,12 @@ RESULTS_HEADING_HTML = """
|
|
| 188 |
|
| 189 |
INPUT_HINT_HTML = """
|
| 190 |
<div style="font-size:12px;color:#4A4E60;margin-top:-4px;padding-bottom:4px;">
|
| 191 |
-
Tip — paste your description and code above, then click
|
| 192 |
-
|
| 193 |
</div>
|
| 194 |
"""
|
| 195 |
|
|
|
|
| 196 |
def build_ui(evaluate_fn):
|
| 197 |
|
| 198 |
def _split_metrics(metrics_str: str):
|
|
@@ -209,32 +250,13 @@ def build_ui(evaluate_fn):
|
|
| 209 |
def _ui_evaluate(description: str, code: str):
|
| 210 |
verdict, metrics, issues, error = evaluate_fn(description, code)
|
| 211 |
accuracy, summary = _split_metrics(metrics)
|
| 212 |
-
|
| 213 |
-
if error:
|
| 214 |
-
# Error occurred — show only the error box, hide all result boxes
|
| 215 |
-
return (
|
| 216 |
-
gr.update(value="", visible=False), # verdict
|
| 217 |
-
gr.update(value="", visible=False), # accuracy
|
| 218 |
-
gr.update(value="", visible=False), # summary
|
| 219 |
-
gr.update(value="", visible=False), # issues
|
| 220 |
-
gr.update(value=error, visible=True), # error ← only this shows
|
| 221 |
-
)
|
| 222 |
-
|
| 223 |
-
# No error — show all result boxes, hide the error box
|
| 224 |
if "PASS" in verdict.upper():
|
| 225 |
verdict_display = "✅ PASS"
|
| 226 |
elif "FAIL" in verdict.upper():
|
| 227 |
verdict_display = "❌ FAIL"
|
| 228 |
else:
|
| 229 |
verdict_display = verdict or ""
|
| 230 |
-
|
| 231 |
-
return (
|
| 232 |
-
gr.update(value=verdict_display, visible=True), # verdict
|
| 233 |
-
gr.update(value=accuracy, visible=True), # accuracy
|
| 234 |
-
gr.update(value=summary, visible=True), # summary
|
| 235 |
-
gr.update(value=issues, visible=True), # issues
|
| 236 |
-
gr.update(value="", visible=False), # error ← hidden when no error
|
| 237 |
-
)
|
| 238 |
|
| 239 |
with gr.Blocks(title="Python Code Evaluator") as ui:
|
| 240 |
|
|
@@ -253,18 +275,10 @@ def build_ui(evaluate_fn):
|
|
| 253 |
max_lines=20,
|
| 254 |
elem_id="desc-input",
|
| 255 |
)
|
| 256 |
-
|
|
|
|
| 257 |
label="Python Code",
|
| 258 |
-
|
| 259 |
-
"# Paste your Python code here…\n\n"
|
| 260 |
-
"# Note: Ensure proper indentation for accurate evaluation.\n\n"
|
| 261 |
-
"def example(numbers):\n"
|
| 262 |
-
" total = 0\n"
|
| 263 |
-
" for item in numbers:\n"
|
| 264 |
-
" if item % 2 == 0:\n"
|
| 265 |
-
" total += item\n"
|
| 266 |
-
" return total\n"
|
| 267 |
-
),
|
| 268 |
lines=10,
|
| 269 |
max_lines=30,
|
| 270 |
elem_id="code-input",
|
|
@@ -275,26 +289,45 @@ def build_ui(evaluate_fn):
|
|
| 275 |
with gr.Row():
|
| 276 |
eval_btn = gr.Button("Evaluate", variant="primary",
|
| 277 |
elem_id="eval-btn", scale=0)
|
| 278 |
-
clear_btn = gr.Button("Clear",
|
| 279 |
elem_id="clear-btn", scale=0)
|
| 280 |
|
| 281 |
gr.HTML(RESULTS_HEADING_HTML)
|
| 282 |
|
| 283 |
with gr.Row(equal_height=True):
|
| 284 |
-
verdict_out
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
label="Status / Errors",
|
| 293 |
interactive=False,
|
| 294 |
-
|
| 295 |
-
elem_id="error-out",
|
| 296 |
scale=1,
|
| 297 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
gr.HTML("""
|
| 300 |
<div style="text-align:right;font-size:11px;color:#4A4E60;margin-top:8px;">
|
|
@@ -306,8 +339,6 @@ def build_ui(evaluate_fn):
|
|
| 306 |
|
| 307 |
outputs = [verdict_out, accuracy_out, summary_out, issues_out, error_out]
|
| 308 |
eval_btn.click(fn=_ui_evaluate, inputs=[description_input, code_input], outputs=outputs)
|
| 309 |
-
description_input.submit(fn=_ui_evaluate, inputs=[description_input, code_input], outputs=outputs)
|
| 310 |
-
code_input.submit(fn=_ui_evaluate, inputs=[description_input, code_input], outputs=outputs)
|
| 311 |
|
| 312 |
def _clear():
|
| 313 |
return "", "", "", "", "", ""
|
|
|
|
| 4 |
# ---------------------------------------------------------------------------
|
| 5 |
# MODULE 1 — UI Module
|
| 6 |
# ---------------------------------------------------------------------------
|
| 7 |
+
|
| 8 |
CUSTOM_CSS = """
|
| 9 |
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');
|
| 10 |
*, *::before, *::after { box-sizing: border-box; }
|
|
|
|
| 41 |
color: #E8EAF0 !important;
|
| 42 |
margin: 0 !important;
|
| 43 |
}
|
| 44 |
+
.eval-header p {
|
| 45 |
+
font-size: 13px !important;
|
| 46 |
+
color: #9DA0B0 !important;
|
| 47 |
+
margin: 2px 0 0 !important;
|
| 48 |
+
}
|
| 49 |
.eval-header .model-badge {
|
| 50 |
margin-left: auto;
|
| 51 |
font-family: 'Space Mono', monospace;
|
|
|
|
| 81 |
.gradio-textbox textarea::placeholder {
|
| 82 |
color: #4A4E60 !important;
|
| 83 |
}
|
| 84 |
+
#code-input {
|
| 85 |
+
min-height: 300px;
|
| 86 |
+
}
|
| 87 |
+
#code-input .cm-editor {
|
| 88 |
+
min-height: 300px;
|
| 89 |
}
|
| 90 |
.gradio-textbox label span,
|
| 91 |
.gradio-code label span {
|
|
|
|
| 109 |
transition: background 0.15s, transform 0.1s !important;
|
| 110 |
letter-spacing: -0.1px !important;
|
| 111 |
}
|
| 112 |
+
#eval-btn:hover {
|
| 113 |
+
background: #7F77DD !important;
|
| 114 |
+
transform: translateY(-1px) !important;
|
| 115 |
+
}
|
| 116 |
+
#eval-btn:active {
|
| 117 |
+
transform: translateY(0) !important;
|
| 118 |
+
}
|
| 119 |
#clear-btn {
|
| 120 |
background: transparent !important;
|
| 121 |
border: 1px solid #3A3E52 !important;
|
|
|
|
| 127 |
cursor: pointer !important;
|
| 128 |
transition: border-color 0.15s, color 0.15s !important;
|
| 129 |
}
|
| 130 |
+
#clear-btn:hover {
|
| 131 |
+
border-color: #7F77DD !important;
|
| 132 |
+
color: #E8EAF0 !important;
|
| 133 |
+
}
|
| 134 |
.results-heading {
|
| 135 |
font-size: 11px !important;
|
| 136 |
font-weight: 500 !important;
|
|
|
|
| 142 |
margin-bottom: 20px !important;
|
| 143 |
}
|
| 144 |
#verdict-out textarea {
|
| 145 |
+
background: #161820 !important;
|
| 146 |
+
border: 1px solid #2E3140 !important;
|
| 147 |
+
border-radius: 10px !important;
|
| 148 |
+
font-family: 'Space Mono', monospace !important;
|
| 149 |
+
font-size: 26px !important;
|
| 150 |
+
font-weight: 700 !important;
|
| 151 |
+
text-align: center !important;
|
| 152 |
+
padding: 20px !important;
|
| 153 |
+
color: #E8EAF0 !important;
|
| 154 |
+
cursor: default !important;
|
| 155 |
}
|
| 156 |
#accuracy-out textarea {
|
| 157 |
+
background: #161820 !important;
|
| 158 |
+
border: 1px solid #2E3140 !important;
|
| 159 |
+
border-radius: 10px !important;
|
| 160 |
+
font-family: 'Space Mono', monospace !important;
|
| 161 |
+
font-size: 26px !important;
|
| 162 |
+
font-weight: 700 !important;
|
| 163 |
+
text-align: center !important;
|
| 164 |
+
padding: 20px !important;
|
| 165 |
+
color: #E8EAF0 !important;
|
| 166 |
+
cursor: default !important;
|
| 167 |
}
|
| 168 |
#summary-out textarea {
|
| 169 |
+
background: #161820 !important;
|
| 170 |
+
border: 1px solid #2E3140 !important;
|
| 171 |
+
border-radius: 10px !important;
|
| 172 |
+
font-family: 'DM Sans', sans-serif !important;
|
| 173 |
+
font-size: 13.5px !important;
|
| 174 |
+
line-height: 1.7 !important;
|
| 175 |
+
padding: 16px !important;
|
| 176 |
+
color: #C0C3D0 !important;
|
| 177 |
+
cursor: default !important;
|
| 178 |
}
|
| 179 |
#issues-out textarea {
|
| 180 |
+
background: #161820 !important;
|
| 181 |
+
border: 1px solid #2E3140 !important;
|
| 182 |
+
border-radius: 10px !important;
|
| 183 |
+
font-family: 'DM Sans', sans-serif !important;
|
| 184 |
+
font-size: 13.5px !important;
|
| 185 |
+
line-height: 1.8 !important;
|
| 186 |
+
padding: 16px !important;
|
| 187 |
+
color: #C0C3D0 !important;
|
| 188 |
+
cursor: default !important;
|
| 189 |
+
min-height: 120px !important;
|
| 190 |
}
|
| 191 |
#error-out textarea {
|
| 192 |
background: #1A0E0E !important;
|
|
|
|
| 197 |
padding: 14px 16px !important;
|
| 198 |
color: #F0997B !important;
|
| 199 |
cursor: default !important;
|
|
|
|
|
|
|
| 200 |
}
|
| 201 |
+
.divider {
|
| 202 |
+
height: 1px;
|
| 203 |
+
background: #2E3140;
|
| 204 |
+
margin: 20px 0;
|
| 205 |
+
}
|
| 206 |
footer { display: none !important; }
|
| 207 |
+
.gradio-container > .wrap > footer { display: none !important; }
|
| 208 |
+
::-webkit-scrollbar { width: 6px; height: 6px; }
|
| 209 |
+
::-webkit-scrollbar-track { background: transparent; }
|
| 210 |
+
::-webkit-scrollbar-thumb { background: #3A3E52; border-radius: 3px; }
|
| 211 |
::-webkit-scrollbar-thumb:hover { background: #534AB7; }
|
| 212 |
"""
|
| 213 |
|
| 214 |
HEADER_HTML = """
|
| 215 |
<div class="eval-header">
|
| 216 |
<div class="logo">🔍</div>
|
| 217 |
+
<div>
|
| 218 |
+
<h1>Python Code Evaluator</h1>
|
| 219 |
+
</div>
|
| 220 |
+
<div class="model-badge">GEMMA-3 · 4B-IT</div>
|
| 221 |
</div>
|
| 222 |
"""
|
| 223 |
|
|
|
|
| 228 |
|
| 229 |
INPUT_HINT_HTML = """
|
| 230 |
<div style="font-size:12px;color:#4A4E60;margin-top:-4px;padding-bottom:4px;">
|
| 231 |
+
Tip — paste your description and code above, then click <strong style="color:#7F77DD">Evaluate</strong>.
|
| 232 |
+
Token limit: 2 048 per request.
|
| 233 |
</div>
|
| 234 |
"""
|
| 235 |
|
| 236 |
+
|
| 237 |
def build_ui(evaluate_fn):
|
| 238 |
|
| 239 |
def _split_metrics(metrics_str: str):
|
|
|
|
| 250 |
def _ui_evaluate(description: str, code: str):
|
| 251 |
verdict, metrics, issues, error = evaluate_fn(description, code)
|
| 252 |
accuracy, summary = _split_metrics(metrics)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
if "PASS" in verdict.upper():
|
| 254 |
verdict_display = "✅ PASS"
|
| 255 |
elif "FAIL" in verdict.upper():
|
| 256 |
verdict_display = "❌ FAIL"
|
| 257 |
else:
|
| 258 |
verdict_display = verdict or ""
|
| 259 |
+
return verdict_display, accuracy, summary, issues, error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
with gr.Blocks(title="Python Code Evaluator") as ui:
|
| 262 |
|
|
|
|
| 275 |
max_lines=20,
|
| 276 |
elem_id="desc-input",
|
| 277 |
)
|
| 278 |
+
|
| 279 |
+
code_input = gr.Code(
|
| 280 |
label="Python Code",
|
| 281 |
+
language="python",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
lines=10,
|
| 283 |
max_lines=30,
|
| 284 |
elem_id="code-input",
|
|
|
|
| 289 |
with gr.Row():
|
| 290 |
eval_btn = gr.Button("Evaluate", variant="primary",
|
| 291 |
elem_id="eval-btn", scale=0)
|
| 292 |
+
clear_btn = gr.Button("Clear", variant="secondary",
|
| 293 |
elem_id="clear-btn", scale=0)
|
| 294 |
|
| 295 |
gr.HTML(RESULTS_HEADING_HTML)
|
| 296 |
|
| 297 |
with gr.Row(equal_height=True):
|
| 298 |
+
verdict_out = gr.Textbox(
|
| 299 |
+
label="Verdict",
|
| 300 |
+
interactive=False,
|
| 301 |
+
elem_id="verdict-out",
|
| 302 |
+
scale=1,
|
| 303 |
+
)
|
| 304 |
+
accuracy_out = gr.Textbox(
|
| 305 |
+
label="Accuracy",
|
|
|
|
| 306 |
interactive=False,
|
| 307 |
+
elem_id="accuracy-out",
|
|
|
|
| 308 |
scale=1,
|
| 309 |
)
|
| 310 |
+
summary_out = gr.Textbox(
|
| 311 |
+
label="Summary",
|
| 312 |
+
interactive=False,
|
| 313 |
+
lines=3,
|
| 314 |
+
elem_id="summary-out",
|
| 315 |
+
scale=2,
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
issues_out = gr.Textbox(
|
| 319 |
+
label="Issues Detected",
|
| 320 |
+
interactive=False,
|
| 321 |
+
lines=5,
|
| 322 |
+
elem_id="issues-out",
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
error_out = gr.Textbox(
|
| 326 |
+
label="Status / Errors",
|
| 327 |
+
interactive=False,
|
| 328 |
+
visible=True,
|
| 329 |
+
elem_id="error-out",
|
| 330 |
+
)
|
| 331 |
|
| 332 |
gr.HTML("""
|
| 333 |
<div style="text-align:right;font-size:11px;color:#4A4E60;margin-top:8px;">
|
|
|
|
| 339 |
|
| 340 |
outputs = [verdict_out, accuracy_out, summary_out, issues_out, error_out]
|
| 341 |
eval_btn.click(fn=_ui_evaluate, inputs=[description_input, code_input], outputs=outputs)
|
|
|
|
|
|
|
| 342 |
|
| 343 |
def _clear():
|
| 344 |
return "", "", "", "", "", ""
|