Team Ai
Apppublic

rachumallupavan/JavaCodeAssistant

sourceHugging Faceupdated 27d agoView on Hugging Face
0likes
app.py65 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4# Load instruction model5generator = pipeline(6    "text-generation")7 8 9def review_java_code(code):10 11    if not code.strip():12        return "Please paste Java code."13 14    prompt = f"""15You are a Senior Java Architect.16 17Review the following Java code.18 19Provide:20 211. Summary222. Bugs233. Performance Issues244. Security Issues255. Java Best Practices266. Rating out of 1027 28Java Code:29 30{code}31"""32 33    result = generator(34        prompt,35        max_new_tokens=300,36        do_sample=False37    )38 39    return result[0]["generated_text"]40 41 42demo = gr.Interface(43    fn=review_java_code,44    inputs=gr.Code(45        language="java",46        label="Paste Java Code"47    ),48    outputs=gr.Textbox(49        label="AI Review",50        lines=2051    ),52    title="☕ Java Code Review Assistant",53    description="""54Paste any Java code and receive an AI-generated review covering:55 56• Bugs57• Performance58• Security59• Best Practices60• Overall Rating61"""62)63 64if __name__ == "__main__":65    demo.launch()