Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -144,7 +144,7 @@ class SyntaxFixerApp:
|
|
| 144 |
return "No history available."
|
| 145 |
|
| 146 |
history_text = "=== Fix History ===\n"
|
| 147 |
-
for entry in self.history:
|
| 148 |
history_text += f"Timestamp: {entry['timestamp']}\n"
|
| 149 |
history_text += f"Language: {entry['language']}\n"
|
| 150 |
history_text += f"Broken Code:\n{entry['broken_code']}\n"
|
|
@@ -191,7 +191,9 @@ def create_gradio_interface():
|
|
| 191 |
|
| 192 |
with gr.Accordion("History of Fixes", open=False):
|
| 193 |
history_output = gr.Textbox(label="Fix History", lines=10)
|
| 194 |
-
|
|
|
|
|
|
|
| 195 |
|
| 196 |
with gr.Accordion("About & License", open=False):
|
| 197 |
gr.Markdown("""
|
|
@@ -206,36 +208,52 @@ def create_gradio_interface():
|
|
| 206 |
def update_code_language(language):
|
| 207 |
return gr.update(language=language)
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
fix_button.click(
|
| 210 |
-
fn=
|
| 211 |
inputs=[code_input, language_dropdown],
|
| 212 |
-
outputs=code_output
|
| 213 |
)
|
|
|
|
|
|
|
| 214 |
example_button.click(
|
| 215 |
fn=app.load_example,
|
| 216 |
inputs=language_dropdown,
|
| 217 |
outputs=code_input
|
| 218 |
)
|
|
|
|
|
|
|
| 219 |
clear_button.click(
|
| 220 |
fn=lambda: "",
|
| 221 |
inputs=None,
|
| 222 |
outputs=code_input
|
| 223 |
)
|
|
|
|
|
|
|
| 224 |
language_dropdown.change(
|
| 225 |
fn=update_code_language,
|
| 226 |
-
|
| 227 |
outputs=code_input
|
| 228 |
)
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
| 231 |
inputs=None,
|
| 232 |
outputs=history_output
|
| 233 |
)
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
| 236 |
inputs=None,
|
| 237 |
-
outputs=history_output
|
| 238 |
-
_js="() => {return []}" # Ensure history updates after fixing
|
| 239 |
)
|
| 240 |
|
| 241 |
return demo
|
|
|
|
| 144 |
return "No history available."
|
| 145 |
|
| 146 |
history_text = "=== Fix History ===\n"
|
| 147 |
+
for entry in self.history[-5:]: # Show only last 5 entries to avoid too much text
|
| 148 |
history_text += f"Timestamp: {entry['timestamp']}\n"
|
| 149 |
history_text += f"Language: {entry['language']}\n"
|
| 150 |
history_text += f"Broken Code:\n{entry['broken_code']}\n"
|
|
|
|
| 191 |
|
| 192 |
with gr.Accordion("History of Fixes", open=False):
|
| 193 |
history_output = gr.Textbox(label="Fix History", lines=10)
|
| 194 |
+
with gr.Row():
|
| 195 |
+
refresh_history_button = gr.Button("Refresh History")
|
| 196 |
+
clear_history_button = gr.Button("Clear History")
|
| 197 |
|
| 198 |
with gr.Accordion("About & License", open=False):
|
| 199 |
gr.Markdown("""
|
|
|
|
| 208 |
def update_code_language(language):
|
| 209 |
return gr.update(language=language)
|
| 210 |
|
| 211 |
+
def fix_and_update_history(code, language):
|
| 212 |
+
"""Fix code and return both fixed code and updated history."""
|
| 213 |
+
fixed = app.fix_syntax(code, language)
|
| 214 |
+
history = app.get_history()
|
| 215 |
+
return fixed, history
|
| 216 |
+
|
| 217 |
+
# Main fix button - fixes code and updates history
|
| 218 |
fix_button.click(
|
| 219 |
+
fn=fix_and_update_history,
|
| 220 |
inputs=[code_input, language_dropdown],
|
| 221 |
+
outputs=[code_output, history_output]
|
| 222 |
)
|
| 223 |
+
|
| 224 |
+
# Load example button
|
| 225 |
example_button.click(
|
| 226 |
fn=app.load_example,
|
| 227 |
inputs=language_dropdown,
|
| 228 |
outputs=code_input
|
| 229 |
)
|
| 230 |
+
|
| 231 |
+
# Clear input button
|
| 232 |
clear_button.click(
|
| 233 |
fn=lambda: "",
|
| 234 |
inputs=None,
|
| 235 |
outputs=code_input
|
| 236 |
)
|
| 237 |
+
|
| 238 |
+
# Language dropdown change - updates code editor language
|
| 239 |
language_dropdown.change(
|
| 240 |
fn=update_code_language,
|
| 241 |
+
inputs=language_dropdown,
|
| 242 |
outputs=code_input
|
| 243 |
)
|
| 244 |
+
|
| 245 |
+
# Refresh history button
|
| 246 |
+
refresh_history_button.click(
|
| 247 |
+
fn=app.get_history,
|
| 248 |
inputs=None,
|
| 249 |
outputs=history_output
|
| 250 |
)
|
| 251 |
+
|
| 252 |
+
# Clear history button
|
| 253 |
+
clear_history_button.click(
|
| 254 |
+
fn=app.clear_history,
|
| 255 |
inputs=None,
|
| 256 |
+
outputs=history_output
|
|
|
|
| 257 |
)
|
| 258 |
|
| 259 |
return demo
|