Skip to content

Commit beebe75

Browse files
authored
Add files via upload
1 parent 364626b commit beebe75

14 files changed

+322
-0
lines changed

Brion_class.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def handle_input(self):
2+
user_input = self.entry.get()
3+
self.output_box.insert(tk.END, f"You: {user_input}\n")
4+
5+
# Send user_input to the LLM
6+
code = self.brion.generate_code(user_input)
7+
8+
# Display the generated code
9+
self.output_box.insert(tk.END, f"Assistant:\n{code}\n\n")
10+
self.entry.delete(0, tk.END)

Code display.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
self.output_box.insert(tk.END, "Assistant:\n")
2+
self.output_box.insert(tk.END, code + "\n\n", "code")
3+
4+
# Apply the 'code' tag to style code blocks
5+
self.output_box.tag_config('code', font=('Courier', 10), foreground='blue')

Message_handling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def handle_input(self):
2+
user_input = self.entry.get()
3+
self.output_box.insert(tk.END, f"You: {user_input}\n")
4+
5+
# Send user_input to the LLM
6+
code = self.brion.generate_code(user_input)
7+
8+
# Display the generated code
9+
self.output_box.insert(tk.END, f"Assistant:\n{code}\n\n")
10+
self.entry.delete(0, tk.END)

Tkinter application update.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import tkinter as tk
2+
from tkinter import scrolledtext
3+
import openai
4+
5+
class BrionApp:
6+
def __init__(self, root):
7+
self.root = root
8+
self.root.title("Brion Assistant")
9+
self.root.geometry("600x600")
10+
11+
self.conversation = []
12+
13+
self.output_box = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=70, height=30)
14+
self.output_box.pack(pady=10)
15+
16+
self.entry = tk.Entry(root, width=70)
17+
self.entry.pack(pady=5)
18+
19+
self.send_button = tk.Button(root, text="Send", command=self.handle_input)
20+
self.send_button.pack(pady=5)
21+
22+
def handle_input(self):
23+
user_input = self.entry.get()
24+
self.output_box.insert(tk.END, f"You: {user_input}\n")
25+
self.entry.delete(0, tk.END)
26+
27+
brion = Brion()
28+
response = brion.generate_code(user_input)
29+
30+
self.output_box.insert(tk.END, f"Assistant:\n{response}\n\n", 'code')
31+
self.output_box.tag_config('code', font=('Courier', 10), foreground='blue')
32+
33+
# Optionally, execute the code
34+
# self.execute_generated_code(response)
35+
36+
class Brion:
37+
def __init__(self):
38+
# Initialize conversation history
39+
self.conversation = []
40+
41+
def generate_code(self, user_input):
42+
self.conversation.append({"role": "user", "content": user_input})
43+
44+
messages = [{"role": msg["role"], "content": msg["content"]} for msg in self.conversation]
45+
46+
response = openai.ChatCompletion.create(
47+
model="gpt-4o",
48+
messages=messages
49+
)
50+
51+
assistant_message = response.choices[0].message["content"]
52+
self.conversation.append({"role": "assistant", "content": assistant_message})
53+
54+
return assistant_message
55+
56+
if __name__ == "__main__":
57+
root = tk.Tk()
58+
app = BrionApp(root)
59+
root.mainloop()

Web_based_interface.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from flask import Flask, render_template, request, jsonify
2+
import openai
3+
4+
app = Flask(__name__)
5+
6+
@app.route('/')
7+
def index():
8+
return render_template('index.html')
9+
10+
@app.route('/generate_code', methods=['POST'])
11+
def generate_code():
12+
data = request.get_json()
13+
user_input = data['message']
14+
15+
# Call the LLM as before
16+
response = openai.Completion.create(
17+
engine="gpt-4o",
18+
prompt=f"Convert the following description into Python code:\n\n{user_input}",
19+
max_tokens=150
20+
)
21+
22+
code = response.choices[0].text.strip()
23+
return jsonify({'code': code})
24+
25+
if __name__ == '__main__':
26+
app.run(debug=True)

brion.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import openai
2+
3+
class Brion:
4+
def __init__(self):
5+
self.conversation = []
6+
7+
def generate_code(self, user_input):
8+
self.conversation.append({"role": "user", "content": user_input})
9+
10+
messages = self.conversation.copy()
11+
12+
response = openai.ChatCompletion.create(
13+
model="gpt-4o",
14+
messages=messages
15+
)
16+
17+
assistant_message = response.choices[0].message["content"]
18+
self.conversation.append({"role": "assistant", "content": assistant_message})
19+
20+
return assistant_message
21+
22+
def correct_code(self, code, error_message):
23+
prompt = f"""
24+
The following Python code contains an error:
25+
26+
```python
27+
{code}
28+
```
29+
30+
The error message is:
31+
{error_message}
32+
33+
Please provide a corrected version of the code.
34+
35+
Corrected Code:
36+
"""
37+
38+
response = openai.Completion.create(
39+
engine="gpt-4o",
40+
prompt=prompt,
41+
max_tokens=300,
42+
temperature=0
43+
)
44+
45+
corrected_code = response.choices[0].text.strip()
46+
return corrected_code

brion_app.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import tkinter as tk
2+
from tkinter import scrolledtext
3+
from brion import Brion
4+
5+
class BrionApp:
6+
def __init__(self, root):
7+
self.root = root
8+
self.root.title("Brion Assistant")
9+
self.root.geometry("600x600")
10+
11+
self.output_box = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=70, height=30)
12+
self.output_box.pack(pady=10)
13+
14+
self.entry = tk.Entry(root, width=70)
15+
self.entry.pack(pady=5)
16+
self.entry.bind('<Return>', lambda event: self.handle_input())
17+
18+
self.send_button = tk.Button(root, text="Send", command=self.handle_input)
19+
self.send_button.pack(pady=5)
20+
21+
self.brion = Brion()
22+
23+
def handle_input(self):
24+
user_input = self.entry.get()
25+
if not user_input.strip():
26+
return
27+
self.output_box.insert(tk.END, f"You: {user_input}\n")
28+
self.entry.delete(0, tk.END)
29+
30+
code = self.brion.generate_code(user_input)
31+
self.output_box.insert(tk.END, f"Assistant:\n{code}\n\n", 'code')
32+
self.output_box.tag_config('code', font=('Courier', 10), foreground='blue')
33+
34+
# Attempt to execute the code
35+
self.execute_generated_code(code)
36+
37+
def execute_generated_code(self, code):
38+
self.output_box.insert(tk.END, "Executing generated code...\n")
39+
try:
40+
exec_locals = {}
41+
exec(code, {}, exec_locals)
42+
output = exec_locals.get('output', '')
43+
if output:
44+
self.output_box.insert(tk.END, f"Execution Output:\n{output}\n\n")
45+
else:
46+
self.output_box.insert(tk.END, "Code executed successfully.\n\n")
47+
except Exception as e:
48+
self.output_box.insert(tk.END, f"Error during execution: {e}\n\n", 'error')
49+
self.output_box.tag_config('error', foreground='red')
50+
51+
# Attempt to correct the code
52+
self.output_box.insert(tk.END, "Attempting to correct the code...\n")
53+
corrected_code = self.brion.correct_code(code, str(e))
54+
self.output_box.insert(tk.END, f"Assistant Corrected Code:\n{corrected_code}\n\n", 'code')
55+
self.output_box.tag_config('code', font=('Courier', 10), foreground='green')
56+
57+
# Re-attempt execution with corrected code
58+
self.output_box.insert(tk.END, "Re-executing corrected code...\n")
59+
try:
60+
exec_locals = {}
61+
exec(corrected_code, {}, exec_locals)
62+
output = exec_locals.get('output', '')
63+
if output:
64+
self.output_box.insert(tk.END, f"Execution Output:\n{output}\n\n")
65+
else:
66+
self.output_box.insert(tk.END, "Corrected code executed successfully.\n\n")
67+
except Exception as e:
68+
self.output_box.insert(tk.END, f"Corrected code failed: {e}\n\n", 'error')
69+
70+
if __name__ == "__main__":
71+
root = tk.Tk()
72+
app = BrionApp(root)
73+
root.mainloop()

exampleprompt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Convert the following natural language description into executable Python code:
2+
3+
"{user_input}"

frontend.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!-- index.html -->
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>Brion Assistant</title>
6+
<style>
7+
/* Basic styling for the chat interface */
8+
</style>
9+
</head>
10+
<body>
11+
<div id="chat-container">
12+
<div id="message-display"></div>
13+
<input type="text" id="message-input" placeholder="Type your code request...">
14+
<button id="send-button">Send</button>
15+
</div>
16+
<script>
17+
document.getElementById('send-button').addEventListener('click', sendMessage);
18+
19+
function sendMessage() {
20+
const input = document.getElementById('message-input').value;
21+
const display = document.getElementById('message-display');
22+
display.innerHTML += `<div class="user-message">${input}</div>`;
23+
24+
fetch('/generate_code', {
25+
method: 'POST',
26+
headers: {'Content-Type': 'application/json'},
27+
body: JSON.stringify({message: input})
28+
})
29+
.then(response => response.json())
30+
.then(data => {
31+
display.innerHTML += `<div class="assistant-message"><pre>${data.code}</pre></div>`;
32+
});
33+
}
34+
</script>
35+
</body>
36+
</html>

handle_exception_output.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def execute_generated_code(self, code):
2+
try:
3+
exec_locals = {}
4+
exec(code, {}, exec_locals)
5+
output = exec_locals.get('output', '')
6+
self.output_box.insert(tk.END, f"Execution Output:\n{output}\n\n")
7+
except Exception as e:
8+
self.output_box.insert(tk.END, f"Error during execution: {e}\n\n")

0 commit comments

Comments
 (0)