Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,60 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 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 |
-
send_button = gr.Button("Send", elem_classes="retro-terminal")
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
# Launch the
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|