Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -289,28 +289,100 @@ def process_validator_request(model_name, model_structure, template_instructions
|
|
289 |
print(f"An error occurred: {e}")
|
290 |
return f"An error occurred during generation: {e}"
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
with gr.Blocks(title="C# Validator Generator") as demo:
|
293 |
-
gr.Markdown(""
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
print(f"An error occurred: {e}")
|
290 |
return f"An error occurred during generation: {e}"
|
291 |
|
292 |
+
# with gr.Blocks(title="C# Validator Generator") as demo:
|
293 |
+
# gr.Markdown("""
|
294 |
+
# # C# Validator Code Generator
|
295 |
+
# Use this tool to generate a C# validator class based on your model structure and template instructions,
|
296 |
+
# following a specific architectural pattern.
|
297 |
+
# """)
|
298 |
+
|
299 |
+
# with gr.Row():
|
300 |
+
# with gr.Column():
|
301 |
+
# model_name_input = gr.Textbox(label="Model Name (e.g., Role)", placeholder="Enter the model name (must be a valid C# identifier)...", interactive=True)
|
302 |
+
# model_structure_input = gr.Textbox(label="Model Structure (C# Class Definition)", placeholder="Paste your C# class definition here (including public properties)...", lines=15, interactive=True)
|
303 |
+
# template_instructions_input = gr.Textbox(label="Specific Template Instructions (Optional)", placeholder="Add any specific validation rules (e.g., 'Validate Id as GUID', 'Check if list is not null and not empty')...", lines=5, interactive=True)
|
304 |
+
# generate_button = gr.Button("Generate Validator Code")
|
305 |
+
|
306 |
+
# with gr.Column():
|
307 |
+
# code_output = gr.Code(label="Generated C# Validator Code",lines=25, interactive=False)
|
308 |
+
|
309 |
+
# generate_button.click(
|
310 |
+
# fn=process_validator_request,
|
311 |
+
# inputs=[model_name_input, model_structure_input, template_instructions_input],
|
312 |
+
# outputs=[code_output]
|
313 |
+
# )
|
314 |
+
|
315 |
+
|
316 |
+
# demo.launch()
|
317 |
+
|
318 |
+
import gradio as gr
|
319 |
+
@spaces.GPU
|
320 |
+
def process_multiple_validators(model_names_str, model_structure, template_instructions):
|
321 |
+
model_names = [name.strip() for name in model_names_str.split(",") if name.strip()]
|
322 |
+
files_output = {}
|
323 |
+
|
324 |
+
for model_name in model_names:
|
325 |
+
result = process_validator_request(model_name, model_structure, template_instructions)
|
326 |
+
files_output[model_name] = result
|
327 |
+
|
328 |
+
return files_output
|
329 |
+
|
330 |
+
|
331 |
with gr.Blocks(title="C# Validator Generator") as demo:
|
332 |
+
gr.Markdown("## 🧠 C# Validator Code Generator")
|
333 |
+
|
334 |
+
with gr.Tabs():
|
335 |
+
# Tab 1: Single Model
|
336 |
+
with gr.Tab("Single Validator"):
|
337 |
+
with gr.Row():
|
338 |
+
with gr.Column():
|
339 |
+
model_name_input = gr.Textbox(label="Model Name")
|
340 |
+
model_structure_input = gr.Textbox(label="Model Structure", lines=15)
|
341 |
+
template_input = gr.Textbox(label="Template Instructions (Optional)", lines=4)
|
342 |
+
generate_btn = gr.Button("Generate Validator")
|
343 |
+
|
344 |
+
with gr.Column():
|
345 |
+
single_code_output = gr.Code(label="Generated Code", language="csharp", lines=25)
|
346 |
+
|
347 |
+
generate_btn.click(
|
348 |
+
fn=process_validator_request,
|
349 |
+
inputs=[model_name_input, model_structure_input, template_input],
|
350 |
+
outputs=[single_code_output],
|
351 |
+
)
|
352 |
+
|
353 |
+
# Tab 2: Batch Mode
|
354 |
+
with gr.Tab("Batch Validators"):
|
355 |
+
with gr.Row():
|
356 |
+
with gr.Column():
|
357 |
+
model_names_input = gr.Textbox(
|
358 |
+
label="Model Names (comma-separated)",
|
359 |
+
placeholder="e.g., User, Role, Customer"
|
360 |
+
)
|
361 |
+
shared_model_structure_input = gr.Textbox(label="Shared Model Structure", lines=10)
|
362 |
+
shared_template_input = gr.Textbox(label="Shared Template Instructions (Optional)", lines=3)
|
363 |
+
batch_generate_btn = gr.Button("Generate All")
|
364 |
+
|
365 |
+
with gr.Column():
|
366 |
+
generated_editors = gr.Accordion("Generated Files", open=True)
|
367 |
+
editors_output = gr.Group()
|
368 |
+
|
369 |
+
def render_outputs(files_dict):
|
370 |
+
outputs = []
|
371 |
+
for name, code in files_dict.items():
|
372 |
+
editor = gr.Code(value=code, label=f"{name}.Validator.cs", language="csharp", lines=20)
|
373 |
+
outputs.append(editor)
|
374 |
+
return outputs
|
375 |
+
|
376 |
+
batch_generate_btn.click(
|
377 |
+
fn=process_multiple_validators,
|
378 |
+
inputs=[model_names_input, shared_model_structure_input, shared_template_input],
|
379 |
+
outputs=editors_output,
|
380 |
+
preprocess=False,
|
381 |
+
postprocess=True,
|
382 |
+
show_progress=True
|
383 |
+
)
|
384 |
+
|
385 |
+
generated_editors.children.append(editors_output)
|
386 |
+
|
387 |
+
|
388 |
+
demo.launch()
|