Spaces:
Runtime error
Runtime error
File size: 2,739 Bytes
d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 8574d0e d2a5db4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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() |