luisoala commited on
Commit
6ffe97c
Β·
1 Parent(s): 4e3dced
Files changed (1) hide show
  1. app.py +56 -26
app.py CHANGED
@@ -70,18 +70,14 @@ def create_ui():
70
  with gr.Group():
71
  # Validation results
72
  validation_results = gr.HTML(visible=False)
73
- with gr.Row():
74
- report_text = gr.Textbox(
75
- label="Detailed Report",
76
- visible=False,
77
- show_copy_button=True,
78
- lines=10
79
- )
80
- report_md = gr.File(
81
- label="Download Report",
82
- visible=False,
83
- file_types=[".md"]
84
- )
85
 
86
  # Define CSS for the validation UI
87
  gr.HTML("""
@@ -191,11 +187,30 @@ def create_ui():
191
  else:
192
  return "url", """<div class="progress-status">Enter a URL to fetch</div>""", gr.update(visible=False)
193
 
 
 
 
 
 
 
 
 
 
194
  def on_file_upload(file):
195
  if file is None:
196
- return """<div class="progress-status">Ready for upload</div>""", gr.update(visible=False)
 
 
 
 
 
197
 
198
- return """<div class="progress-status">βœ… File uploaded successfully</div>""", gr.update(visible=False)
 
 
 
 
 
199
 
200
  def fetch_from_url(url):
201
  if not url:
@@ -272,30 +287,45 @@ def create_ui():
272
 
273
  def on_validate(file):
274
  if file is None:
275
- return [gr.update(visible=False)] * 3
 
 
 
 
276
 
277
  # Process the file and get results
278
  results, report = process_file(file)
279
 
280
- # Save report to file
281
- if report:
282
- report_path = "validation_report.md"
283
- with open(report_path, "w") as f:
284
- f.write(report)
285
 
286
  return [
287
  build_results_html(results),
288
- gr.update(visible=True, value=report) if report else gr.update(visible=False),
289
- gr.update(visible=True, value="validation_report.md") if report else gr.update(visible=False)
290
  ]
291
 
292
  # Connect UI events to functions
293
  tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
294
- file_input.change(on_file_upload, inputs=file_input, outputs=[upload_progress, validation_results])
 
 
 
 
295
  validate_btn.click(
296
- on_validate,
297
- inputs=file_input,
298
- outputs=[validation_results, report_text, report_md]
 
 
 
 
 
 
 
 
 
 
299
  )
300
  fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
301
 
 
70
  with gr.Group():
71
  # Validation results
72
  validation_results = gr.HTML(visible=False)
73
+
74
+ # Report button and options in an expandable group
75
+ with gr.Group(visible=False) as report_group:
76
+ gr.Markdown("### Validation Report")
77
+ with gr.Row():
78
+ copy_btn = gr.Button("πŸ“‹ Copy to Clipboard")
79
+ download_btn = gr.Button("⬇️ Download as .md")
80
+ report_text = gr.Textbox(visible=False) # Hidden textbox to store report content
 
 
 
 
81
 
82
  # Define CSS for the validation UI
83
  gr.HTML("""
 
187
  else:
188
  return "url", """<div class="progress-status">Enter a URL to fetch</div>""", gr.update(visible=False)
189
 
190
+ def on_copy_click(report):
191
+ return report
192
+
193
+ def on_download_click(report, file_name):
194
+ report_file = f"report_{file_name}.md"
195
+ with open(report_file, "w") as f:
196
+ f.write(report)
197
+ return report_file
198
+
199
  def on_file_upload(file):
200
  if file is None:
201
+ return [
202
+ """<div class="progress-status">Ready for upload</div>""",
203
+ gr.update(visible=False),
204
+ gr.update(visible=False),
205
+ None
206
+ ]
207
 
208
+ return [
209
+ """<div class="progress-status">βœ… File uploaded successfully</div>""",
210
+ gr.update(visible=False),
211
+ gr.update(visible=False),
212
+ None
213
+ ]
214
 
215
  def fetch_from_url(url):
216
  if not url:
 
287
 
288
  def on_validate(file):
289
  if file is None:
290
+ return [
291
+ gr.update(visible=False),
292
+ gr.update(visible=False),
293
+ None
294
+ ]
295
 
296
  # Process the file and get results
297
  results, report = process_file(file)
298
 
299
+ # Only show report options if validation was successful
300
+ report_visible = any(passed for passed, _, _ in results)
 
 
 
301
 
302
  return [
303
  build_results_html(results),
304
+ gr.update(visible=report_visible),
305
+ report if report else None
306
  ]
307
 
308
  # Connect UI events to functions
309
  tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
310
+ file_input.change(
311
+ on_file_upload,
312
+ inputs=file_input,
313
+ outputs=[upload_progress, validation_results, report_group, report_text]
314
+ )
315
  validate_btn.click(
316
+ on_validate,
317
+ inputs=file_input,
318
+ outputs=[validation_results, report_group, report_text]
319
+ )
320
+ copy_btn.click(
321
+ on_copy_click,
322
+ inputs=report_text,
323
+ outputs=report_text # This triggers the copy
324
+ )
325
+ download_btn.click(
326
+ on_download_click,
327
+ inputs=[report_text, file_input],
328
+ outputs=gr.File()
329
  )
330
  fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
331