Spaces:
Running
Running
File size: 10,111 Bytes
9c3d10b c824607 4103cdb c824607 b8284a1 9c3d10b b8284a1 3fde40c 4cc64ba 284e677 374bf21 ce05652 374bf21 787b430 1cbf14e a6d6883 374bf21 284e677 15dc550 284e677 3fde40c b8284a1 3fde40c 15dc550 217f347 9c3d10b ce05652 3fde40c e363c7d 3fde40c 284e677 27eff0a 96eb585 aa40e0e 1325d7d 167ff63 aa40e0e ce05652 4103cdb ce05652 4103cdb ce05652 e363c7d 3fde40c 4cc64ba add7b09 4cc64ba add7b09 aa40e0e add7b09 aa40e0e add7b09 aa40e0e add7b09 aa40e0e 167ff63 27eff0a ce05652 4103cdb aa40e0e add7b09 1536913 add7b09 c3f6c7c 3fde40c e363c7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
import gradio as gr
import sys
import pandas as pd
sys.path.insert(0, "ASG.API/")
from ASGModels import ASG
ASGAI=ASG(isForm=False)
choices=[
"Group",
"Technique",
"Software"
]
model_choices = gr.Dropdown(
choices=choices,
label="اختر النموذج",
value="Group",
)
import gradio as gr
def home_page():
return """
<div class="px-4 py-5 my-5 text-center">
<img class="d-block mx-auto mb-4" src="/docs/5.0/assets/brand/bootstrap-logo.svg" alt="" width="72" height="57">
<h1 class="display-5 fw-bold">مرحباً بك في Model AI ASG
</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">
Wasm-Speeker We provide models that help to aid in the creation of different attack sequences. You can deal with AGS models by choosing the model you want. We provide models that help to aid in the creation of different attack sequences. You can deal with AGS models by choosing the model you want. </p>
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
<button type="button" class="btn btn-primary btn-lg px-4 gap-3">Primary button</button>
<button type="button" class="btn btn-outline-secondary btn-lg px-4">Secondary</button>
</div>
</div>
</div>
<div class="container col-xxl-8 px-4 py-5">
<div class="row flex-lg-row-reverse align-items-center g-5 py-5">
<div class="col-10 col-sm-8 col-lg-6">
<img src="bootstrap-themes.png" class="d-block mx-lg-auto img-fluid" alt="Bootstrap Themes" width="700" height="500" loading="lazy">
</div>
<div class="col-lg-6">
<h1 class="display-5 fw-bold lh-1 mb-3">Responsive left-aligned hero with image</h1>
<p class="lead">Quickly design and customize responsive mobile-first sites with Bootstrap, the world’s most popular front-end open source toolkit, featuring Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful JavaScript plugins.</p>
<div class="d-grid gap-2 d-md-flex justify-content-md-start">
<button type="button" class="btn btn-primary btn-lg px-4 me-md-2">Primary</button>
<button type="button" class="btn btn-outline-secondary btn-lg px-4">Default</button>
</div>
</div>
</div>
</div>
<div class="row p-4 pb-0 pe-lg-0 pt-lg-5 align-items-center rounded-3 border shadow-lg">
<div class="col-lg-7 p-3 p-lg-5 pt-lg-3">
<h1 class="display-4 fw-bold lh-1">Border hero with cropped image and shadows</h1>
<p class="lead">Quickly design and customize responsive mobile-first sites with Bootstrap, the world’s most popular front-end open source toolkit, featuring Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful JavaScript plugins.</p>
<div class="d-grid gap-2 d-md-flex justify-content-md-start mb-4 mb-lg-3">
<button type="button" class="btn btn-primary btn-lg px-4 me-md-2 fw-bold">Primary</button>
<button type="button" class="btn btn-outline-secondary btn-lg px-4">Default</button>
</div>
</div>
<div class="col-lg-4 offset-lg-1 p-0 overflow-hidden shadow-lg">
<img class="rounded-lg-3" src="bootstrap-docs.png" alt="" width="720">
</div>
</div>
<div class="bg-dark text-secondary px-4 py-5 text-center">
<div >
<h1 class="display-5 fw-bold text-white">Dark mode hero</h1>
<div class="col-lg-6 mx-auto">
<p class="fs-5 mb-4">Quickly design and customize responsive mobile-first sites with Bootstrap, the world’s most popular front-end open source toolkit, featuring Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful JavaScript plugins.</p>
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
<button type="button" class="btn btn-outline-info btn-lg px-4 me-sm-3 fw-bold">Custom button</button>
<button type="button" class="btn btn-outline-light btn-lg px-4">Secondary</button>
</div>
</div>
</div>
</div>
"""
def format_cyber_response(user_question: str, raw_answer: str, model="gpt-4") -> str:
"""
Uses an AI model to rephrase a raw cyber answer into a professionally structured response
according to the style and tone of the user question.
"""
prompt = f"""
You are an expert technical writer and cybersecurity analyst.
Your task is to take the following user question and raw answer related to MITRE ATT&CK framework
or cyberattack scenario generation, and rewrite the answer professionally based on the nature
and tone of the question.
Instructions:
1. Analyze the question to detect whether it is asking for an explanation, summary, technical analysis, or use-case scenario.
2. Rewrite the raw answer to match the expected response style (educational, technical, formal, or analytical).
3. Use domain-appropriate terminology.
4. Make the output coherent, structured, and professionally written.
---
Question:
{user_question}
Raw Answer:
{raw_answer}
---
Final Response:
"""
return prompt
from gradio_client import Client
def ask_ai(message ):
client = Client("wasmdashai/T2T")
result = client.predict(
text=message,
key="AIzaSyC85_3TKmiXtOpwybhSFThZdF1nGKlxU5c",
api_name="/predict"
)
return result
from gradio_client import Client
def ask_wasm(txt):
client = Client("wasmdashai/LAHJA-AI")
result = client.predict(
prompt=txt,
api_name="/generate_from_prompt"
)
return result
def t2t(text, namn_model):
if namn_model == "Group":
out = ASGAI.Group.predictAPI(text)
elif namn_model == "Technique":
out = ASGAI.Tec.predictAPI(text)
else:
out = ASGAI.Soft.predictAPI(text)
txt=format_cyber_response(text,str(out))
# anwai=ask_ai(txt)
return txt
def t2seq(text, namn_model):
if namn_model == "Group":
out = ASGAI.Group.Predict_ALL(text)
elif namn_model == "Technique":
out = ASGAI.Tec.Predict_ALL(text)
else:
out = ASGAI.Soft.Predict_ALL(text)
txt=format_cyber_response(text,str(out))
# anwai=ask_wasm(txt)
return txt
def echo(message, history):
text=t2seq(message,"Group")
return text
import uuid
def s2s(text):
userid=str(uuid.uuid4())
datase=[]
def addsenario(inputs):
data, pd = inputs
seqtactic = ''
seqtec = ''
for ob in data[0]:
seqtactic += ob[0] + "$@"
seqtec += ob[1] + "$@"
out, _ = ASGAI.Soft.predictAPI(seqtec)
out2, _ = ASGAI.Group.predictAPI(seqtec + " " + out)
score = f"{out2}@{out}@{data[1][1]}@{round(data[2], 2)}"
tutorial = {
"seqtactic": seqtactic,
"iduser": userid,
"seqtec": seqtec,
"score": score
}
datase.append(tutorial)
return tutorial
ASGAI.cks.onsequens=addsenario
text_output=ASGAI.search([text],numstop=50)
df = pd.DataFrame(datase)
return df
# Use Blocks
with gr.Blocks() as demo:
gr.HTML("""
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title> Model AI ASG</title>
</head>
""")
# العنوان الرئيسي
gr.Markdown("# Model AI ASG")
# عرض الصورة الترحيبية
gr.Image("icon (1).jpg", label="Model AI ASG")
gr.HTML("""
<style>
.gradio-tabs {
direction: rtl;
}
</style>
""")
with gr.Row():
with gr.Tab("Home"):
gr.HTML(home_page())
with gr.Tab("Thread Base"):
gr.Markdown("### Thread Base")
with gr.Row():
with gr.Tab("T2T"):
text_input = gr.Textbox(label="Input Text")
model_choices = gr.Dropdown(choices=["Group", "Technique", "Soft"], label="Model",value="Group",)
text_output = gr.Textbox(label="Output")
submit_btn = gr.Button("Submit")
submit_btn.click(fn=t2t, inputs=[text_input, model_choices], outputs=text_output)
with gr.Tab("T2Seq"):
text_input_seq = gr.Textbox(label="Input Text")
model_choices_seq = gr.Dropdown(choices=["Group", "Technique", "Soft"], label="Model",value="Group",)
text_output_seq = gr.Textbox(label="Output")
submit_btn_seq = gr.Button("Submit")
submit_btn_seq.click(fn=t2seq, inputs=[text_input_seq, model_choices_seq], outputs=text_output_seq)
with gr.Tab("T2Sinaro"):
model_choices_seq1 = gr.Dropdown(choices=["Group", "Technique", "Soft"], label="Model",value="Group",)
gr.ChatInterface(fn=echo, title="Echo Bot")
with gr.Tab("T2Sinaror"):
text_input_seqttt = gr.Textbox(label="Input Text")
submit_btn_seqtt = gr.Button("Submit")
text_out_seqttt = gr.Dataframe(headers=["seqtactic", "iduser", "seqtec", "score"], datatype="str", label="Output")
submit_btn_seqtt.click(fn=s2s, inputs=[text_input_seqttt], outputs=text_out_seqttt)
with gr.Tab("Stute Base"):
gr.Markdown("### Stute Base")
demo.launch()
# demo.launch()
|