File size: 1,135 Bytes
0cad702
f6a1e93
0cad702
 
 
f6a1e93
0cad702
 
ef06e2c
 
0cad702
 
 
 
 
 
a35556f
0cad702
 
 
 
 
f6a1e93
ae81c61
f6a1e93
 
 
 
 
 
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
27
28
29
30
31
32
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

# Load GraphCodeBERT model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("microsoft/graphcodebert-base")
model = AutoModelForCausalLM.from_pretrained("microsoft/graphcodebert-base")

# Define input and output interfaces
input = gr.Textbox(lines=5, label="Input")
output = gr.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=5000)
  # Decode output
  output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
  # Return output
  return output

# Create and launch Gradio interface
iface = gr.Interface( # Use from_pretrained instead of from_pipeline
    fn=use_graphcodebert, 
    inputs=input, 
    outputs=output,
    title="GraphCodeBERT Code Synthesis", # Add a title for the web app
    description="Enter a natural language query and get a code snippet generated by GraphCodeBERT.", # Add a description for the web app
)
iface.launch()