Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
import flake8
|
| 4 |
import autopep8
|
| 5 |
|
| 6 |
def lint_code(code):
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def main():
|
| 11 |
with gr.Interface(
|
| 12 |
fn=lint_code,
|
| 13 |
inputs="text",
|
| 14 |
-
outputs="text",
|
| 15 |
title="PyLintPro",
|
| 16 |
-
description="A Gradio app that helps users improve Python code to meet Flake8 and PEP 8 standards."
|
|
|
|
| 17 |
) as demo:
|
| 18 |
demo.launch()
|
| 19 |
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import flake8
|
| 3 |
import autopep8
|
| 4 |
|
| 5 |
def lint_code(code):
|
| 6 |
+
# Initialize Flake8 style guide
|
| 7 |
+
style_guide = flake8.get_style_guide()
|
| 8 |
+
# Create a checker for the provided code
|
| 9 |
+
checker = style_guide.check_files([code])
|
| 10 |
+
# Collect linting issues
|
| 11 |
+
issues = [f"{issue.filename}:{issue.line_number}: {issue.text}" for issue in checker.get_statistics('')]
|
| 12 |
+
# Format the code using AutoPEP8
|
| 13 |
+
formatted_code = autopep8.fix_code(code)
|
| 14 |
+
return "\n".join(issues), formatted_code
|
| 15 |
|
| 16 |
def main():
|
| 17 |
with gr.Interface(
|
| 18 |
fn=lint_code,
|
| 19 |
inputs="text",
|
| 20 |
+
outputs=["text", "text"],
|
| 21 |
title="PyLintPro",
|
| 22 |
+
description="A Gradio app that helps users improve Python code to meet Flake8 and PEP 8 standards.",
|
| 23 |
+
live=True
|
| 24 |
) as demo:
|
| 25 |
demo.launch()
|
| 26 |
|