|
import tkinter as tk |
|
from tkinter import ttk, filedialog |
|
import openai |
|
|
|
|
|
openai.api_key = "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" |
|
|
|
|
|
root = tk.Tk() |
|
root.title("Opentrons Protocol Generator") |
|
|
|
|
|
input_label = ttk.Label(root, text="Enter protocol requirements:") |
|
input_label.pack(pady=5) |
|
input_text = tk.Text(root, height=10, width=50) |
|
input_text.pack(pady=5) |
|
|
|
|
|
def generate_protocol(): |
|
requirements = input_text.get("1.0", "end-1c") |
|
protocol_code = generate_code_from_requirements(requirements) |
|
save_protocol_file(protocol_code) |
|
|
|
generate_button = ttk.Button(root, text="Generate Protocol", command=generate_protocol) |
|
generate_button.pack(pady=5) |
|
|
|
|
|
def generate_code_from_requirements(requirements): |
|
response = openai.Completion.create( |
|
engine="code-davinci-002", |
|
prompt=f"Generate a Python protocol for the Opentrons Flex robot based on the following requirements:\n\n{requirements}", |
|
max_tokens=1024, |
|
n=1, |
|
stop=None, |
|
temperature=0.7, |
|
) |
|
|
|
protocol_code = response.choices[0].text |
|
return protocol_code |
|
|
|
|
|
def save_protocol_file(protocol_code): |
|
file_path = filedialog.asksaveasfilename(defaultextension=".py", filetypes=[("Python Files", "*.py")]) |
|
if file_path: |
|
with open(file_path, "w") as file: |
|
file.write(protocol_code) |
|
|
|
|
|
root.mainloop() |