dash-asg / app.py
wasmdashai's picture
Update app.py
4103cdb verified
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()