Spaces:
Running
Running
Commit
·
f2c0071
1
Parent(s):
37c68ce
download risks
Browse files- .gitignore +2 -1
- app.py +3 -1
- executor.py +14 -2
.gitignore
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
.DS_Store
|
| 2 |
.env
|
| 3 |
scratch.py
|
| 4 |
-
__pycache__
|
|
|
|
|
|
| 1 |
.DS_Store
|
| 2 |
.env
|
| 3 |
scratch.py
|
| 4 |
+
__pycache__
|
| 5 |
+
static/download.json
|
app.py
CHANGED
|
@@ -81,6 +81,7 @@ class UI:
|
|
| 81 |
)
|
| 82 |
self.mitigations_text = gr.Markdown()
|
| 83 |
self.mitigations = gr.DataFrame(label=None, visible=False)
|
|
|
|
| 84 |
|
| 85 |
gr.Markdown("---")
|
| 86 |
gr.Markdown("<br>")
|
|
@@ -109,9 +110,10 @@ class UI:
|
|
| 109 |
self.model_name_or_path,
|
| 110 |
self.taxonomy
|
| 111 |
],
|
| 112 |
-
outputs=[self.assessment_sec, self.risks, self.assessed_risks],
|
| 113 |
api_name="risk_identifier"
|
| 114 |
)
|
|
|
|
| 115 |
self.assessed_risks.select(
|
| 116 |
fn=mitigations,
|
| 117 |
inputs=[self.assessed_risks, self.taxonomy],
|
|
|
|
| 81 |
)
|
| 82 |
self.mitigations_text = gr.Markdown()
|
| 83 |
self.mitigations = gr.DataFrame(label=None, visible=False)
|
| 84 |
+
self.download = gr.DownloadButton("Download JSON", visible=False)
|
| 85 |
|
| 86 |
gr.Markdown("---")
|
| 87 |
gr.Markdown("<br>")
|
|
|
|
| 110 |
self.model_name_or_path,
|
| 111 |
self.taxonomy
|
| 112 |
],
|
| 113 |
+
outputs=[self.assessment_sec, self.risks, self.assessed_risks, self.download],
|
| 114 |
api_name="risk_identifier"
|
| 115 |
)
|
| 116 |
+
|
| 117 |
self.assessed_risks.select(
|
| 118 |
fn=mitigations,
|
| 119 |
inputs=[self.assessed_risks, self.taxonomy],
|
executor.py
CHANGED
|
@@ -10,7 +10,9 @@ import json
|
|
| 10 |
from typing import List, Dict, Any
|
| 11 |
import pandas as pd
|
| 12 |
import gradio as gr
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
from risk_atlas_nexus.blocks.inference import WMLInferenceEngine
|
| 16 |
from risk_atlas_nexus.blocks.inference.params import WMLInferenceEngineParams
|
|
@@ -48,11 +50,21 @@ def risk_identifier(usecase: str,
|
|
| 48 |
sample_labels = [r.name if r else r.id for r in risks]
|
| 49 |
|
| 50 |
out_sec = gr.Markdown("""<h2> Potential Risks </h2> """)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
#return out_df
|
| 53 |
return out_sec, gr.State(risks), gr.Dataset(samples=[r.id for r in risks],
|
| 54 |
sample_labels=sample_labels,
|
| 55 |
-
samples_per_page=50, visible=True, label="Estimated by an LLM.")
|
| 56 |
|
| 57 |
|
| 58 |
@lru_cache
|
|
|
|
| 10 |
from typing import List, Dict, Any
|
| 11 |
import pandas as pd
|
| 12 |
import gradio as gr
|
| 13 |
+
import datetime
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
import json
|
| 16 |
|
| 17 |
from risk_atlas_nexus.blocks.inference import WMLInferenceEngine
|
| 18 |
from risk_atlas_nexus.blocks.inference.params import WMLInferenceEngineParams
|
|
|
|
| 50 |
sample_labels = [r.name if r else r.id for r in risks]
|
| 51 |
|
| 52 |
out_sec = gr.Markdown("""<h2> Potential Risks </h2> """)
|
| 53 |
+
|
| 54 |
+
# write out a JSON
|
| 55 |
+
data = {'time': str(datetime.datetime.now(datetime.timezone.utc)),
|
| 56 |
+
'intent': usecase,
|
| 57 |
+
'model': model_name_or_path,
|
| 58 |
+
'taxonomy': taxonomy,
|
| 59 |
+
'risks': [json.loads(r.json()) for r in risks]
|
| 60 |
+
}
|
| 61 |
+
file_path = Path("static/download.json")
|
| 62 |
+
file_path.write_text(json.dumps(data, indent=4), encoding='utf-8')
|
| 63 |
|
| 64 |
#return out_df
|
| 65 |
return out_sec, gr.State(risks), gr.Dataset(samples=[r.id for r in risks],
|
| 66 |
sample_labels=sample_labels,
|
| 67 |
+
samples_per_page=50, visible=True, label="Estimated by an LLM."), gr.DownloadButton("Download JSON", visible=True, value="static/download.json")
|
| 68 |
|
| 69 |
|
| 70 |
@lru_cache
|