Spaces:
Runtime error
Runtime error
Commit ·
55352c2
1
Parent(s): 932d07c
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
# Load the fine-tuned model and tokenizer
|
| 6 |
-
model_path = "Asna-DifiNative/AIBuddy" # Path to the pretrained fine-tuned model
|
| 7 |
-
model = BartForConditionalGeneration.from_pretrained(model_path)
|
| 8 |
-
tokenizer = BartTokenizer.from_pretrained(model_path)
|
| 9 |
-
|
| 10 |
-
# Translate function using the fine-tuned model
|
| 11 |
-
def translate_instruction(context, input_text):
|
| 12 |
-
full_input = context + " " + input_text
|
| 13 |
-
input_ids = tokenizer.encode(full_input, truncation=True, return_tensors='pt')
|
| 14 |
-
with torch.no_grad():
|
| 15 |
-
outputs = model.generate(input_ids, max_length=50, num_beams=4, early_stopping=True)
|
| 16 |
-
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 17 |
-
return translated_text
|
| 18 |
-
|
| 19 |
-
# Example instructions (without context)
|
| 20 |
-
example_instructions = [
|
| 21 |
-
"Show me a list of pods in the current namespace.",
|
| 22 |
-
"Display the pods running in the 'development' namespace.",
|
| 23 |
-
"List all pods in the 'production' environment.",
|
| 24 |
-
"How can I see the pods in the 'testing' namespace?",
|
| 25 |
-
"What command should I use to get the list of containers?"
|
| 26 |
-
]
|
| 27 |
|
| 28 |
# Gradio Interface
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=translate_instruction,
|
| 31 |
inputs=[
|
| 32 |
-
|
| 33 |
gr.inputs.Textbox(label="Enter Human Instruction")
|
| 34 |
],
|
| 35 |
outputs=gr.outputs.Textbox(label="Generated CLI Command")
|
|
|
|
| 1 |
+
# Create context element
|
| 2 |
+
context_element = gr.inputs.Textbox(lines=3, label="Context")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Gradio Interface
|
| 5 |
iface = gr.Interface(
|
| 6 |
fn=translate_instruction,
|
| 7 |
inputs=[
|
| 8 |
+
context_element,
|
| 9 |
gr.inputs.Textbox(label="Enter Human Instruction")
|
| 10 |
],
|
| 11 |
outputs=gr.outputs.Textbox(label="Generated CLI Command")
|