Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from src.utils.dataset_loader import load_dataset
|
| 3 |
+
from src.models.model import load_model, run_inference
|
| 4 |
+
|
| 5 |
+
# Load dataset
|
| 6 |
+
df = load_dataset()
|
| 7 |
+
|
| 8 |
+
# List of available models (example)
|
| 9 |
+
models = ["Canstralian/text2shellcommands", "Canstralian/RabbitRedux", "Canstralian/CySec_Known_Exploit_Analyzer"]
|
| 10 |
+
prompt_ids = df.index.tolist() if df is not None else []
|
| 11 |
+
|
| 12 |
+
# Function to simulate conversation with model selection
|
| 13 |
+
def chat_interface(user_input, selected_model, prompt_id=None):
|
| 14 |
+
if df is not None and prompt_id is not None:
|
| 15 |
+
prompt = df.iloc[prompt_id]["prompt_text"] # Replace with the actual column name
|
| 16 |
+
# Run inference on the selected model
|
| 17 |
+
response = run_inference(user_input, selected_model, prompt)
|
| 18 |
+
else:
|
| 19 |
+
response = f"[{selected_model}] says: You entered '{user_input}'. This is a simulated response."
|
| 20 |
+
return response
|
| 21 |
+
|
| 22 |
+
# Gradio Interface
|
| 23 |
+
with gr.Blocks(css="./static/styles.css") as demo:
|
| 24 |
+
with gr.Row():
|
| 25 |
+
gr.Markdown("### Retro Hacker Chat with Debugging Prompts", elem_classes="retro-terminal")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
user_input = gr.Textbox(
|
| 28 |
+
label="Enter your message:",
|
| 29 |
+
placeholder="Type your message here...",
|
| 30 |
+
elem_classes="retro-terminal"
|
| 31 |
+
)
|
| 32 |
+
model_selector = gr.Dropdown(
|
| 33 |
+
choices=models,
|
| 34 |
+
label="Select Model",
|
| 35 |
+
value=models[0],
|
| 36 |
+
elem_classes="retro-terminal"
|
| 37 |
+
)
|
| 38 |
+
if prompt_ids:
|
| 39 |
+
prompt_selector = gr.Dropdown(
|
| 40 |
+
choices=prompt_ids,
|
| 41 |
+
label="Select Debugging Prompt ID",
|
| 42 |
+
value=prompt_ids[0],
|
| 43 |
+
elem_classes="retro-terminal"
|
| 44 |
+
)
|
| 45 |
+
else:
|
| 46 |
+
prompt_selector = None
|
| 47 |
+
with gr.Row():
|
| 48 |
+
response_box = gr.Textbox(
|
| 49 |
+
label="Model Response:",
|
| 50 |
+
placeholder="The model's response will appear here...",
|
| 51 |
+
elem_classes="retro-terminal"
|
| 52 |
+
)
|
| 53 |
+
with gr.Row():
|
| 54 |
+
send_button = gr.Button("Send", elem_classes="retro-terminal")
|
| 55 |
+
|
| 56 |
+
# Link input and output
|
| 57 |
+
if prompt_selector:
|
| 58 |
+
send_button.click(chat_interface, inputs=[user_input, model_selector, prompt_selector], outputs=response_box)
|
| 59 |
+
else:
|
| 60 |
+
send_button.click(chat_interface, inputs=[user_input, model_selector], outputs=response_box)
|
| 61 |
+
|
| 62 |
+
# Launch the interface
|
| 63 |
+
demo.launch()
|