Spaces:
Runtime error
Runtime error
File size: 1,814 Bytes
6fb8bbb ccffeee 4ddc04c 9391764 4ddc04c ccffeee 4ddc04c ccffeee 4ddc04c f41e052 ccffeee 4ddc04c ccffeee 4ddc04c ccffeee | 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 | import torch
from transformers import BartForConditionalGeneration, BartTokenizer
import gradio as gr
# Load the fine-tuned model and tokenizer
model_path = "difinative/AIBuddy" # Path to the pretrained fine-tuned model
model = BartForConditionalGeneration.from_pretrained(model_path)
tokenizer = BartTokenizer.from_pretrained(model_path)
# Translate function using the fine-tuned model
def translate_instruction(context, input_text):
full_input = context + " " + input_text
input_ids = tokenizer.encode(full_input, truncation=True, return_tensors='pt')
with torch.no_grad():
outputs = model.generate(input_ids, max_length=50, num_beams=4, early_stopping=True)
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return translated_text
# Gradio Interface
iface = gr.Interface(
fn=translate_instruction,
inputs=[
gr.inputs.Textbox(label="Enter Context"),
gr.inputs.Textbox(label="Enter Human Instruction")
],
outputs=gr.outputs.Textbox(label="Generated CLI Command"),
title="CLI Command Generator",
description="<p>This tool generates CLI commands from human instructions and context.</p>"
"<p>Provide a context and human instruction, and click 'Generate' to get the CLI command.</p>",
examples=[
["Pod xyz is called as tiger.", "Show me a list of pods in the current namespace."],
["Nickname of deployment development is cap", "Display the pods running in the cap."],
["Production is also known as", "List all pods in the 'production' environment."],
["Kubernetes", "Show the pods running in the 'testing' namespace?"],
["Docker", "What command should I use to get the list of containers?"]
]
)
# Launch the Gradio app using Ngrok
iface.launch() |