Spaces:
Runtime error
Runtime error
import gradio as gr | |
import subprocess | |
import time | |
from datetime import datetime | |
# Function to run Aider and get the enhancement | |
def run_aider(input_text): | |
try: | |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
input_file = "temp_input_file.txt" | |
# Save the input text to a temporary file | |
with open(input_file, "w") as f: | |
f.write(input_text) | |
# Run the aider-chat command | |
command = [ | |
"aider-chat", input_file, | |
"--map-refresh=always", | |
"--yes", | |
"--model=ollama/mistral", | |
"--message", | |
"Analyze the current logic and UI, and enhance and optimize the existing functionality with high-impact improvements. Focus on core functionality improvements such as better state management, performance optimization, enhanced UI/UX, or any feature that users would love. Ensure all changes are internal to the app and do not rely on external API keys or services. If no files are provided, create the necessary components from scratch." | |
] | |
# Run the Aider command and capture the output | |
result = subprocess.run(command, capture_output=True, text=True) | |
if result.returncode == 0: | |
return f"[{timestamp}] Enhancement completed successfully:\n\n{result.stdout}" | |
else: | |
return f"[{timestamp}] Enhancement encountered an issue:\n\n{result.stderr}" | |
except Exception as e: | |
return f"An error occurred: {str(e)}" | |
# Function to handle continuous analysis and enhancement | |
def continuous_enhancement(input_text, max_iterations=10): | |
for iteration in range(1, max_iterations + 1): | |
result = run_aider(input_text) | |
yield f"Iteration {iteration}:\n{result}\n\n{'-'*50}\n" | |
time.sleep(3600) # Wait for an hour before the next iteration | |
# Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown("## Continuous Code Enhancement with Aider-Chat") | |
input_text = gr.TextArea( | |
label="Paste the code or text to be analyzed and enhanced", | |
placeholder="Paste your code here...", | |
lines=20 | |
) | |
max_iterations = gr.Number( | |
label="Number of Iterations", | |
value=10, | |
precision=0, | |
minimum=1, | |
step=1 | |
) | |
output = gr.Textbox( | |
label="Enhancement Output", | |
placeholder="Output will be displayed here...", | |
lines=20 | |
) | |
enhance_button = gr.Button("Start Enhancement") | |
enhance_button.click( | |
continuous_enhancement, | |
inputs=[input_text, max_iterations], | |
outputs=output, | |
stream=True # Stream the output | |
) | |
# Launch the Gradio app | |
demo.launch() |