Spaces:
Runtime error
Runtime error
Commit ·
6fb8bbb
1
Parent(s): 55352c2
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Create context element
|
| 2 |
context_element = gr.inputs.Textbox(lines=3, label="Context")
|
| 3 |
|
|
@@ -12,4 +39,4 @@ iface = gr.Interface(
|
|
| 12 |
)
|
| 13 |
|
| 14 |
# Launch the Gradio app using Ngrok
|
| 15 |
-
iface.launch(examples=[[
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
| 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 |
# Create context element
|
| 29 |
context_element = gr.inputs.Textbox(lines=3, label="Context")
|
| 30 |
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
# Launch the Gradio app using Ngrok
|
| 42 |
+
iface.launch(examples=[[context, instruction] for instruction in example_instructions])
|