jens-l commited on
Commit
a49b090
·
1 Parent(s): 1b6a051

Add ruff pre-commit configuration and improve code formatting

Browse files
Files changed (5) hide show
  1. .pre-commit-config.yaml +15 -0
  2. README.md +1 -1
  3. app.py +24 -17
  4. pyproject.toml +28 -0
  5. uv.lock +0 -0
.pre-commit-config.yaml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: check-added-large-files
9
+
10
+ - repo: https://github.com/astral-sh/ruff-pre-commit
11
+ rev: v0.8.4
12
+ hooks:
13
+ - id: ruff
14
+ args: [--fix]
15
+ - id: ruff-format
README.md CHANGED
@@ -2,4 +2,4 @@
2
  It's almost Lovable - Build Gradio apps, using only a chat interface.
3
 
4
  ## Notes
5
- - Use as little custom css as possible!!!
 
2
  It's almost Lovable - Build Gradio apps, using only a chat interface.
3
 
4
  ## Notes
5
+ - Use as little custom css as possible!!!
app.py CHANGED
@@ -1,7 +1,7 @@
1
- import gradio as gr
2
- import time
3
  import random
 
4
 
 
5
 
6
  gr.NO_RELOAD = False
7
 
@@ -31,17 +31,24 @@ def get_preview_content():
31
  return """
32
  <div style="padding: 20px; font-family: Arial, sans-serif;">
33
  <h2>Preview - Generated App</h2>
34
- <div style="border: 1px solid #ddd; padding: 15px; margin: 10px 0; border-radius: 8px;">
 
35
  <h3>Todo App</h3>
36
- <input type="text" placeholder="Add a new task..." style="width: 70%; padding: 8px; margin-right: 10px;">
37
- <button style="padding: 8px 15px; background: #007bff; color: white; border: none; border-radius: 4px;">Add</button>
 
 
38
  <ul style="margin-top: 15px; list-style-type: none; padding: 0;">
39
- <li style="padding: 8px; border-bottom: 1px solid #eee;">✓ Learn Gradio</li>
40
- <li style="padding: 8px; border-bottom: 1px solid #eee;">✓ Build awesome UIs</li>
41
- <li style="padding: 8px; border-bottom: 1px solid #eee;">⬜ Deploy to HuggingFace</li>
 
 
 
42
  </ul>
43
  </div>
44
- <p style="color: #666; font-size: 14px;">This is a live preview of your generated application.</p>
 
45
  </div>
46
  """
47
 
@@ -58,33 +65,33 @@ def add_task(new_task, tasks):
58
  def create_todo_app():
59
  with gr.Blocks() as app:
60
  gr.Markdown("# Todo App")
61
-
62
  with gr.Row():
63
  new_task = gr.Textbox(
64
- placeholder="Add a new task...",
65
  scale=3,
66
  container=False
67
  )
68
  add_btn = gr.Button("Add", scale=1)
69
-
70
  task_list = gr.Dataframe(
71
  headers=["Tasks"],
72
  datatype=["str"],
73
  interactive=False
74
  )
75
-
76
  add_btn.click(
77
  add_task,
78
  inputs=[new_task, task_list],
79
  outputs=[new_task, task_list]
80
  )
81
-
82
  new_task.submit(
83
  add_task,
84
  inputs=[new_task, task_list],
85
  outputs=[new_task, task_list]
86
  )
87
-
88
  return app
89
 
90
  if __name__ == "__main__":
@@ -133,7 +140,7 @@ def create_lovable_ui():
133
  # "Deploy to HF Spaces", variant="secondary", scale=1
134
  # )
135
 
136
- preview_html = gr.HTML(value=get_preview_content())
137
 
138
  # Code Tab
139
  with gr.TabItem("Code"):
@@ -164,7 +171,7 @@ def create_lovable_ui():
164
  # "Deploy to HF Spaces", variant="secondary", scale=1
165
  # )
166
 
167
- code_view = gr.Code(
168
  value=get_code_content(),
169
  language="python",
170
  lines=20,
 
 
 
1
  import random
2
+ import time
3
 
4
+ import gradio as gr
5
 
6
  gr.NO_RELOAD = False
7
 
 
31
  return """
32
  <div style="padding: 20px; font-family: Arial, sans-serif;">
33
  <h2>Preview - Generated App</h2>
34
+ <div style="border: 1px solid #ddd; padding: 15px; margin: 10px 0;
35
+ border-radius: 8px;">
36
  <h3>Todo App</h3>
37
+ <input type="text" placeholder="Add a new task..."
38
+ style="width: 70%; padding: 8px; margin-right: 10px;">
39
+ <button style="padding: 8px 15px; background: #007bff; color: white;
40
+ border: none; border-radius: 4px;">Add</button>
41
  <ul style="margin-top: 15px; list-style-type: none; padding: 0;">
42
+ <li style="padding: 8px; border-bottom: 1px solid #eee;">
43
+ Learn Gradio</li>
44
+ <li style="padding: 8px; border-bottom: 1px solid #eee;">
45
+ ✓ Build awesome UIs</li>
46
+ <li style="padding: 8px; border-bottom: 1px solid #eee;">
47
+ ⬜ Deploy to HuggingFace</li>
48
  </ul>
49
  </div>
50
+ <p style="color: #666; font-size: 14px;">
51
+ This is a live preview of your generated application.</p>
52
  </div>
53
  """
54
 
 
65
  def create_todo_app():
66
  with gr.Blocks() as app:
67
  gr.Markdown("# Todo App")
68
+
69
  with gr.Row():
70
  new_task = gr.Textbox(
71
+ placeholder="Add a new task...",
72
  scale=3,
73
  container=False
74
  )
75
  add_btn = gr.Button("Add", scale=1)
76
+
77
  task_list = gr.Dataframe(
78
  headers=["Tasks"],
79
  datatype=["str"],
80
  interactive=False
81
  )
82
+
83
  add_btn.click(
84
  add_task,
85
  inputs=[new_task, task_list],
86
  outputs=[new_task, task_list]
87
  )
88
+
89
  new_task.submit(
90
  add_task,
91
  inputs=[new_task, task_list],
92
  outputs=[new_task, task_list]
93
  )
94
+
95
  return app
96
 
97
  if __name__ == "__main__":
 
140
  # "Deploy to HF Spaces", variant="secondary", scale=1
141
  # )
142
 
143
+ gr.HTML(value=get_preview_content())
144
 
145
  # Code Tab
146
  with gr.TabItem("Code"):
 
171
  # "Deploy to HF Spaces", variant="secondary", scale=1
172
  # )
173
 
174
+ gr.Code(
175
  value=get_code_content(),
176
  language="python",
177
  lines=20,
pyproject.toml CHANGED
@@ -7,3 +7,31 @@ requires-python = ">=3.12"
7
  dependencies = [
8
  "gradio>=5.32.0",
9
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  dependencies = [
8
  "gradio>=5.32.0",
9
  ]
10
+
11
+ [dependency-groups]
12
+ dev = [
13
+ "ruff>=0.8.0",
14
+ "pre-commit>=4.0.0",
15
+ ]
16
+
17
+ [tool.ruff]
18
+ target-version = "py312"
19
+ line-length = 88
20
+
21
+ [tool.ruff.lint]
22
+ select = [
23
+ "E", # pycodestyle errors
24
+ "W", # pycodestyle warnings
25
+ "F", # pyflakes
26
+ "I", # isort
27
+ "B", # flake8-bugbear
28
+ "C4", # flake8-comprehensions
29
+ "UP", # pyupgrade
30
+ ]
31
+ ignore = []
32
+
33
+ [tool.ruff.format]
34
+ quote-style = "double"
35
+ indent-style = "space"
36
+ skip-magic-trailing-comma = false
37
+ line-ending = "auto"
uv.lock CHANGED
The diff for this file is too large to render. See raw diff