Spaces:
Running
Running
Download app_ui.py from Boobesh007/code-review: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/spaces/Boobesh007/code-review/resolve/main/app_ui.py
- Command line
-
hf download hf://spaces/Boobesh007/code-review/app_ui.py
-
curl -L -o app_ui.py https://huggingface.co/spaces/Boobesh007/code-review/resolve/main/app_ui.py
2.77 kB
| import gradio as gr | |
| import requests | |
| import json | |
| ENV_URL = 'https://boobesh007-code-review.hf.space' | |
| def review_code(code, language, difficulty): | |
| try: | |
| # Reset environment | |
| reset_resp = requests.post(ENV_URL + '/reset', timeout=30) | |
| obs = reset_resp.json() | |
| # Create action based on code analysis | |
| action = { | |
| 'has_syntax_error': ':' not in code and 'def ' in code, | |
| 'quality_score': 0.5, | |
| 'issues': ['code submitted for review'], | |
| 'severity': 'medium' | |
| } | |
| # Step environment | |
| step_resp = requests.post(ENV_URL + '/step', json=action, timeout=30) | |
| result = step_resp.json() | |
| score = result.get('reward', 0.5) | |
| feedback = result.get('feedback', 'Review complete') | |
| task_type = result.get('task_type', difficulty) | |
| # Format output | |
| output = '## π Code Review Results\n\n' | |
| output += f'**Language:** {language}\n\n' | |
| output += f'**Difficulty:** {task_type}\n\n' | |
| output += f'**Score:** {score:.2f}/1.00\n\n' | |
| output += f'**Feedback:** {feedback}\n\n' | |
| if score >= 0.8: | |
| output += 'β **Excellent code quality!**' | |
| elif score >= 0.5: | |
| output += 'β οΈ **Some issues found - review needed**' | |
| else: | |
| output += 'β **Critical issues found - immediate fix needed**' | |
| return output | |
| except Exception as e: | |
| return f'Error: {str(e)}' | |
| # Build UI | |
| with gr.Blocks(title='AI Code Review', theme=gr.themes.Soft()) as demo: | |
| gr.Markdown('# π» AI Code Review Environment') | |
| gr.Markdown('Paste your code below and get instant AI-powered feedback!') | |
| with gr.Row(): | |
| with gr.Column(): | |
| code_input = gr.Textbox( | |
| label='π Your Code', | |
| placeholder='Paste your code here...', | |
| lines=10 | |
| ) | |
| language = gr.Dropdown( | |
| choices=['python', 'javascript', 'java'], | |
| value='python', | |
| label='π Language' | |
| ) | |
| difficulty = gr.Dropdown( | |
| choices=['easy', 'medium', 'hard'], | |
| value='easy', | |
| label='π― Difficulty Level' | |
| ) | |
| submit_btn = gr.Button('π Review Code', variant='primary') | |
| with gr.Column(): | |
| output = gr.Markdown(label='Results') | |
| submit_btn.click( | |
| fn=review_code, | |
| inputs=[code_input, language, difficulty], | |
| outputs=output | |
| ) | |
| gr.Markdown('---') | |
| gr.Markdown('Built with β€οΈ using OpenEnv | [GitHub](https://github.com/boobesh789/Code-review)') | |
| if __name__ == '__main__': | |
| demo.launch(server_name='0.0.0.0', server_port=7860) | |