Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load instruction model | |
| generator = pipeline( | |
| "text2text-generation" | |
| ) | |
| def review_java_code(code): | |
| if not code.strip(): | |
| return "Please paste Java code." | |
| prompt = f""" | |
| You are a Senior Java Architect. | |
| Review the following Java code. | |
| Provide: | |
| 1. Summary | |
| 2. Bugs | |
| 3. Performance Issues | |
| 4. Security Issues | |
| 5. Java Best Practices | |
| 6. Rating out of 10 | |
| Java Code: | |
| {code} | |
| """ | |
| result = generator( | |
| prompt, | |
| max_new_tokens=300, | |
| do_sample=False | |
| ) | |
| return result[0]["generated_text"] | |
| demo = gr.Interface( | |
| fn=review_java_code, | |
| inputs=gr.Code( | |
| language="java", | |
| label="Paste Java Code" | |
| ), | |
| outputs=gr.Textbox( | |
| label="AI Review", | |
| lines=20 | |
| ), | |
| title="☕ Java Code Review Assistant", | |
| description=""" | |
| Paste any Java code and receive an AI-generated review covering: | |
| • Bugs | |
| • Performance | |
| • Security | |
| • Best Practices | |
| • Overall Rating | |
| """ | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |