AIencoder commited on
Commit
7478df4
·
verified ·
1 Parent(s): 6d34b8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -15,7 +15,7 @@ MODEL_NAME = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
15
  DEVICE = "cpu"
16
  DTYPE = torch.float32
17
 
18
- # --- File System Class (Same as before) ---
19
  class FileSystem:
20
  def __init__(self):
21
  self.files = {
@@ -89,6 +89,7 @@ def load_model():
89
  def run_code(code: str) -> Tuple[str, str]:
90
  start_time = time.time()
91
  try:
 
92
  output = f"✓ Code executed successfully\nExecution time: {time.time() - start_time:.4f}s"
93
  return output, ""
94
  except Exception as e:
@@ -139,29 +140,33 @@ def create_diff_view(original: str, modified: str) -> str:
139
  lines_original = original.split('\n')
140
  lines_modified = modified.split('\n')
141
  diff = []
142
- # Very basic diff visualizer
143
  import difflib
144
  for line in difflib.unified_diff(lines_original, lines_modified, lineterm=""):
145
  diff.append(line)
146
  return "\n".join(diff)
147
 
148
- # --- Gradio UI ---
149
- # 1. FIXED THEME DEFINITION
 
 
150
  theme = gr.themes.Default(
151
  font=[gr.themes.GoogleFont('JetBrains Mono'), 'monospace'],
152
  font_mono=[gr.themes.GoogleFont('JetBrains Mono'), 'monospace'],
153
  primary_hue="blue",
154
  neutral_hue="gray",
155
- # radius=0 <-- REMOVED THIS CAUSE OF ERROR
156
  ).set(
157
  button_primary_background_fill="*primary_500",
158
  button_primary_background_fill_hover="*primary_600",
159
  body_background_fill="*neutral_900",
160
  body_text_color="*neutral_50",
161
- radius_size="none" # <-- Added this to achieve square corners
162
  )
163
 
 
164
  css = """
 
 
 
165
  .editor-container { height: 50vh; }
166
  .terminal { height: 15vh; background-color: #1e1e1e; color: #d4d4d4; overflow: auto; }
167
  .diff-view { height: 40vh; overflow: auto; }
@@ -181,7 +186,6 @@ with gr.Blocks(title="Axon Pro - Free AI IDE", theme=theme, css=css) as demo:
181
 
182
  gr.Markdown("# ⚡ Axon Pro — Free AI-Powered Code IDE")
183
 
184
- # 2. FIXED TABS VARIABLE ASSIGNMENT
185
  with gr.Tabs() as main_tabs:
186
  with gr.Tab("Editor", id="editor-tab"):
187
  with gr.Row(equal_height=True):
@@ -241,13 +245,13 @@ with gr.Blocks(title="Axon Pro - Free AI IDE", theme=theme, css=css) as demo:
241
 
242
  status_bar = gr.Markdown(f"**AXON PRO v1.0** | CPU Mode | TinyLlama-1.1B", elem_classes="status-bar")
243
 
244
- # State
245
  current_file_state = gr.State(fs.current_file)
246
  diff_original_state = gr.State("")
247
  diff_modified_state = gr.State("")
248
  diff_mode_state = gr.State(False)
249
 
250
- # Wrappers
251
  def update_file_content(content):
252
  fs.save_file(content)
253
  return fs.get_current_file_content()
@@ -290,7 +294,7 @@ with gr.Blocks(title="Axon Pro - Free AI IDE", theme=theme, css=css) as demo:
290
  new_hist = history + [[prompt, "Generated code available in Diff View"]]
291
  return diff, "", generated, True, new_hist, ""
292
 
293
- # Event Wiring
294
  editor.change(update_file_content, editor, None)
295
  file_list.change(load_file, file_list, [editor, current_file_state])
296
  new_file_btn.click(create_new_file, new_file_name, [file_list, editor])
@@ -299,7 +303,7 @@ with gr.Blocks(title="Axon Pro - Free AI IDE", theme=theme, css=css) as demo:
299
  complete_btn.click(complete_code_wrapper, editor, editor)
300
  clear_btn.click(lambda: "$ _", None, terminal)
301
 
302
- # 3. FIXED TAB SWITCHING (Using main_tabs variable)
303
  explain_btn.click(
304
  explain_code_wrapper, editor,
305
  [diff_view, diff_original_state, diff_modified_state, diff_mode_state]
 
15
  DEVICE = "cpu"
16
  DTYPE = torch.float32
17
 
18
+ # --- File System Class ---
19
  class FileSystem:
20
  def __init__(self):
21
  self.files = {
 
89
  def run_code(code: str) -> Tuple[str, str]:
90
  start_time = time.time()
91
  try:
92
+ # Placeholder for actual execution logic
93
  output = f"✓ Code executed successfully\nExecution time: {time.time() - start_time:.4f}s"
94
  return output, ""
95
  except Exception as e:
 
140
  lines_original = original.split('\n')
141
  lines_modified = modified.split('\n')
142
  diff = []
 
143
  import difflib
144
  for line in difflib.unified_diff(lines_original, lines_modified, lineterm=""):
145
  diff.append(line)
146
  return "\n".join(diff)
147
 
148
+ # --- Gradio UI Configuration ---
149
+
150
+ # 1. THEME FIX: Removed invalid 'radius_size' from .set()
151
+ # We use standard color overrides only.
152
  theme = gr.themes.Default(
153
  font=[gr.themes.GoogleFont('JetBrains Mono'), 'monospace'],
154
  font_mono=[gr.themes.GoogleFont('JetBrains Mono'), 'monospace'],
155
  primary_hue="blue",
156
  neutral_hue="gray",
 
157
  ).set(
158
  button_primary_background_fill="*primary_500",
159
  button_primary_background_fill_hover="*primary_600",
160
  body_background_fill="*neutral_900",
161
  body_text_color="*neutral_50",
162
+ # radius_size="none" <-- REMOVED to prevent TypeError
163
  )
164
 
165
+ # 2. CSS FIX: Added strict border-radius rule for the "square" look
166
  css = """
167
+ /* Force square corners globally */
168
+ * { border-radius: 0 !important; }
169
+
170
  .editor-container { height: 50vh; }
171
  .terminal { height: 15vh; background-color: #1e1e1e; color: #d4d4d4; overflow: auto; }
172
  .diff-view { height: 40vh; overflow: auto; }
 
186
 
187
  gr.Markdown("# ⚡ Axon Pro — Free AI-Powered Code IDE")
188
 
 
189
  with gr.Tabs() as main_tabs:
190
  with gr.Tab("Editor", id="editor-tab"):
191
  with gr.Row(equal_height=True):
 
245
 
246
  status_bar = gr.Markdown(f"**AXON PRO v1.0** | CPU Mode | TinyLlama-1.1B", elem_classes="status-bar")
247
 
248
+ # State management
249
  current_file_state = gr.State(fs.current_file)
250
  diff_original_state = gr.State("")
251
  diff_modified_state = gr.State("")
252
  diff_mode_state = gr.State(False)
253
 
254
+ # Event Handlers
255
  def update_file_content(content):
256
  fs.save_file(content)
257
  return fs.get_current_file_content()
 
294
  new_hist = history + [[prompt, "Generated code available in Diff View"]]
295
  return diff, "", generated, True, new_hist, ""
296
 
297
+ # Binding Events
298
  editor.change(update_file_content, editor, None)
299
  file_list.change(load_file, file_list, [editor, current_file_state])
300
  new_file_btn.click(create_new_file, new_file_name, [file_list, editor])
 
303
  complete_btn.click(complete_code_wrapper, editor, editor)
304
  clear_btn.click(lambda: "$ _", None, terminal)
305
 
306
+ # Tab switching actions
307
  explain_btn.click(
308
  explain_code_wrapper, editor,
309
  [diff_view, diff_original_state, diff_modified_state, diff_mode_state]