File size: 2,364 Bytes
5458788 76ca6c7 5458788 76ca6c7 5458788 76ca6c7 c74fd81 76ca6c7 c74fd81 76ca6c7 c74fd81 76ca6c7 |
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 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import time
import random
# Load the models and tokenizer
model_name = "Canstralian/text2shellcommands" # Choose your model, can be changed based on use case
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Function to generate shell command or response based on the prompt
def generate_shell_command(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=50, num_return_sequences=1)
command = tokenizer.decode(outputs[0], skip_special_tokens=True)
return command
# Function to simulate a retro terminal environment with some 90s hacker vibe
def terminal_ui(prompt):
# Simulate typing effect
fake_typing_effect = [
"Initializing...\n",
"Boot sequence complete...\n",
"Connecting to secure network...\n",
"Accessing restricted files...\n",
"Running diagnostics...\n",
"Command input: " + prompt + "\n"
]
# Adding some suspense and random time delays to create that 'hacker' feel
for line in fake_typing_effect:
time.sleep(random.uniform(0.5, 1.5)) # Simulate typing delay
print(line) # Simulate print to terminal
time.sleep(0.3)
# Get AI-generated response for the command prompt
command_response = generate_shell_command(prompt)
# Simulate result display with some retro terminal feedback
result_output = f"\n[ SYSTEM STATUS: OK ]\n[ {random.choice(['OK', 'ERROR', 'WARNING'])} ]\n\n"
result_output += f"Command executed: {command_response}\n"
result_output += "[ End of output ]"
return result_output
# Create a Gradio interface with a retro terminal design
def retro_terminal_interface(prompt):
result = terminal_ui(prompt)
return result
# Launch the Gradio app with a terminal theme
iface = gr.Interface(
fn=retro_terminal_interface,
inputs=gr.Textbox(placeholder="Type your shell command here...", label="Enter Command:"),
outputs=gr.Textbox(label="Terminal Output", lines=20, interactive=False),
theme="compact", # Use Gradio's built-in compact theme for a terminal-like feel
live=True # Enable live feedback to simulate a real-time terminal experience
)
iface.launch()
|