File size: 853 Bytes
0cad702 |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoModel
# Load GraphCodeBERT model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("microsoft/graphcodebert-base")
model = AutoModel.from_pretrained("microsoft/graphcodebert-base")
# Define input and output interfaces
input = gr.inputs.Textbox(lines=5, label="Input")
output = gr.outputs.Textbox(label="Output")
# Define function to use GraphCodeBERT
def use_graphcodebert(input):
# Encode input
input_ids = tokenizer.encode(input, return_tensors="pt")
# Generate output
output_ids = model.generate(input_ids, max_length=50)
# Decode output
output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
# Return output
return output
# Create and launch Gradio interface
iface = gr.Interface(fn=use_graphcodebert, inputs=input, outputs=output)
iface.launch()
|