Canstralian commited on
Commit
76ca6c7
·
verified ·
1 Parent(s): 2952127

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -38
app.py CHANGED
@@ -1,44 +1,60 @@
1
  import gradio as gr
 
 
 
2
 
3
- # Function to simulate conversation with model selection
4
- def chat_interface(user_input, selected_model):
5
- response = f"[{selected_model}] says: You entered '{user_input}'. This is a simulated response."
6
- return response
7
 
8
- # List of available models
9
- models = ["Canstralian/text2shellcommands", "Canstralian/RabbitRedux", "Canstralian/CySec_Known_Exploit_Analyzer"]
 
 
 
 
10
 
11
- # Gradio Interface
12
- with gr.Blocks(css="./static/styles.css") as demo:
13
- with gr.Row():
14
- gr.Markdown(
15
- "### Welcome to the Retro Hacker Chat! \n"
16
- "_Experience the retro vibe while interacting with your models._",
17
- elem_classes="retro-terminal"
18
- )
19
- with gr.Row():
20
- user_input = gr.Textbox(
21
- label="Enter your message:",
22
- placeholder="Type your message here...",
23
- elem_classes="retro-terminal"
24
- )
25
- model_selector = gr.Dropdown(
26
- choices=models,
27
- label="Select Model",
28
- value=models[0],
29
- elem_classes="retro-terminal"
30
- )
31
- with gr.Row():
32
- response_box = gr.Textbox(
33
- label="Model Response:",
34
- placeholder="The model's response will appear here...",
35
- elem_classes="retro-terminal"
36
- )
37
- with gr.Row():
38
- send_button = gr.Button("Send", elem_classes="retro-terminal")
39
 
40
- # Link input and output
41
- send_button.click(chat_interface, inputs=[user_input, model_selector], outputs=response_box)
 
 
42
 
43
- # Launch the interface
44
- demo.launch()
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import time
4
+ import random
5
 
6
+ # Load the models and tokenizer
7
+ model_name = "Canstralian/text2shellcommands" # Choose your model, can be changed based on use case
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForCausalLM.from_pretrained(model_name)
10
 
11
+ # Function to generate shell command or response based on the prompt
12
+ def generate_shell_command(prompt):
13
+ inputs = tokenizer(prompt, return_tensors="pt")
14
+ outputs = model.generate(**inputs, max_length=50, num_return_sequences=1)
15
+ command = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return command
17
 
18
+ # Function to simulate a retro terminal environment with some 90s hacker vibe
19
+ def terminal_ui(prompt):
20
+ # Simulate typing effect
21
+ fake_typing_effect = [
22
+ "Initializing...\n",
23
+ "Boot sequence complete...\n",
24
+ "Connecting to secure network...\n",
25
+ "Accessing restricted files...\n",
26
+ "Running diagnostics...\n",
27
+ "Command input: " + prompt + "\n"
28
+ ]
29
+
30
+ # Adding some suspense and random time delays to create that 'hacker' feel
31
+ for line in fake_typing_effect:
32
+ time.sleep(random.uniform(0.5, 1.5)) # Simulate typing delay
33
+ print(line) # Simulate print to terminal
34
+ time.sleep(0.3)
35
+
36
+ # Get AI-generated response for the command prompt
37
+ command_response = generate_shell_command(prompt)
38
+
39
+ # Simulate result display with some retro terminal feedback
40
+ result_output = f"\n[ SYSTEM STATUS: OK ]\n[ {random.choice(['OK', 'ERROR', 'WARNING'])} ]\n\n"
41
+ result_output += f"Command executed: {command_response}\n"
42
+ result_output += "[ End of output ]"
43
+
44
+ return result_output
 
45
 
46
+ # Create a Gradio interface with a retro terminal design
47
+ def retro_terminal_interface(prompt):
48
+ result = terminal_ui(prompt)
49
+ return result
50
 
51
+ # Launch the Gradio app with a terminal theme
52
+ iface = gr.Interface(
53
+ fn=retro_terminal_interface,
54
+ inputs=gr.Textbox(placeholder="Type your shell command here...", label="Enter Command:"),
55
+ outputs=gr.Textbox(label="Terminal Output", lines=20, interactive=False),
56
+ theme="compact", # Use Gradio's built-in compact theme for a terminal-like feel
57
+ live=True # Enable live feedback to simulate a real-time terminal experience
58
+ )
59
+
60
+ iface.launch()