ayushraj2349-2's picture
Create app.py
4c5bb9c verified
raw
history blame
865 Bytes
from transformers import AutoModelForCausalLM, AutoTokenizer
import gradio as gr
# Load Hugging Face's CodeGen model
model_name = "Salesforce/codegen-2B-multi"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Function to review Python code
def review_code(code_snippet):
inputs = tokenizer(code_snippet, return_tensors="pt")
outputs = model.generate(**inputs, max_length=512)
reviewed_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
return reviewed_code
# Gradio UI
def check_code(input_code):
return review_code(input_code)
# Create a Gradio Interface
interface = gr.Interface(
fn=check_code,
inputs=gr.Textbox(label="Enter Python Code"),
outputs=gr.Textbox(label="Reviewed Code"),
title="AI Code Reviewer"
)
# Launch the app
interface.launch()