|
| 1 | +import tkinter as tk |
| 2 | +from tkinter import filedialog, messagebox |
| 3 | +from PIL import Image, ImageTk |
| 4 | +from ideeplc.ideeplc_core import main as run_ideeplc |
| 5 | +import argparse |
| 6 | +import sys |
| 7 | +import os |
| 8 | + |
| 9 | + |
| 10 | +def run_prediction(input_path, calibrate, finetune): |
| 11 | + if not input_path: |
| 12 | + messagebox.showerror("Error", "Please select an input file.") |
| 13 | + return |
| 14 | + |
| 15 | + try: |
| 16 | + args = argparse.Namespace( |
| 17 | + input=input_path, |
| 18 | + calibrate=calibrate, |
| 19 | + finetune=finetune, |
| 20 | + save=True, |
| 21 | + log_level="INFO" |
| 22 | + ) |
| 23 | + run_ideeplc(args) |
| 24 | + messagebox.showinfo("Success", "Prediction completed successfully!") |
| 25 | + except Exception as e: |
| 26 | + messagebox.showerror("Prediction Failed", str(e)) |
| 27 | + |
| 28 | + |
| 29 | +def browse_file(entry_field): |
| 30 | + filepath = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")]) |
| 31 | + if filepath: |
| 32 | + entry_field.delete(0, tk.END) |
| 33 | + entry_field.insert(0, filepath) |
| 34 | + |
| 35 | + |
| 36 | +def launch_gui(): |
| 37 | + root = tk.Tk() |
| 38 | + root.title("iDeepLC Predictor") |
| 39 | + root.geometry("600x400") |
| 40 | + root.configure(bg="#f0f0f0") |
| 41 | + |
| 42 | + # Load and display the image |
| 43 | + img_url = "https://github.com/user-attachments/assets/86e9b793-39be-4f62-8119-5c6a333af487" |
| 44 | + img_path = "logo_temp.jpg" |
| 45 | + |
| 46 | + # Download if not exists (for local runs) |
| 47 | + if not os.path.exists(img_path): |
| 48 | + import requests |
| 49 | + with open(img_path, "wb") as f: |
| 50 | + f.write(requests.get(img_url).content) |
| 51 | + |
| 52 | + image = Image.open(img_path) |
| 53 | + image = image.resize((410,240)) |
| 54 | + photo = ImageTk.PhotoImage(image) |
| 55 | + |
| 56 | + image_label = tk.Label(root, image=photo, bg="#f0f0f0") |
| 57 | + image_label.image = photo |
| 58 | + image_label.pack(pady=(10, 0)) |
| 59 | + |
| 60 | + # Input file selection |
| 61 | + frame = tk.Frame(root, bg="#f0f0f0") |
| 62 | + frame.pack(pady=10) |
| 63 | + |
| 64 | + tk.Label(frame, text="Input CSV:", bg="#f0f0f0").grid(row=0, column=0, padx=5, sticky='e') |
| 65 | + input_entry = tk.Entry(frame, width=40) |
| 66 | + input_entry.grid(row=0, column=1, padx=5) |
| 67 | + tk.Button(frame, text="Browse", command=lambda: browse_file(input_entry)).grid(row=0, column=2, padx=5) |
| 68 | + |
| 69 | + # Options |
| 70 | + options_frame = tk.Frame(root, bg="#f0f0f0") |
| 71 | + options_frame.pack(pady=10) |
| 72 | + |
| 73 | + calibrate_var = tk.BooleanVar() |
| 74 | + finetune_var = tk.BooleanVar() |
| 75 | + |
| 76 | + tk.Checkbutton(options_frame, text="Calibrate", variable=calibrate_var, bg="#f0f0f0").pack(side=tk.LEFT, padx=10) |
| 77 | + tk.Checkbutton(options_frame, text="Fine-tune", variable=finetune_var, bg="#f0f0f0").pack(side=tk.LEFT, padx=10) |
| 78 | + |
| 79 | + # Run button |
| 80 | + run_btn = tk.Button(root, text="Run Prediction", bg="#4CAF50", fg="white", font=("Arial", 12, "bold"), |
| 81 | + command=lambda: run_prediction(input_entry.get(), calibrate_var.get(), finetune_var.get())) |
| 82 | + run_btn.pack(pady=20) |
| 83 | + |
| 84 | + root.mainloop() |
| 85 | + |
| 86 | + |
| 87 | +if __name__ == "__main__": |
| 88 | + launch_gui() |
0 commit comments