Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,24 @@
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
-
from shutil import copy
|
| 4 |
import gradio as gr
|
| 5 |
-
from
|
| 6 |
-
from os.path import isdir, isfile, join, realpath
|
| 7 |
from tkinter import Tk
|
| 8 |
from tkinter.filedialog import askdirectory
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# --- Constants ---
|
| 11 |
phases = ["iFAT", "(i)SAT"]
|
| 12 |
inputPhases = {**{i: k for i, k in enumerate(phases)}, **{len(phases): "All"}}
|
| 13 |
-
exitinput = {"no", "n", "0"}
|
| 14 |
regTemplate = r'template'
|
| 15 |
|
| 16 |
# --- Helper Functions ---
|
| 17 |
|
| 18 |
-
# Function to
|
| 19 |
-
def
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
print()
|
| 24 |
-
|
| 25 |
-
# Function to get phase input
|
| 26 |
-
def validatedPhaseInput():
|
| 27 |
-
inputPhase = None
|
| 28 |
-
while inputPhase is None:
|
| 29 |
-
printOptions()
|
| 30 |
-
inputPhase = input()
|
| 31 |
-
|
| 32 |
-
if inputPhase.isnumeric():
|
| 33 |
-
inputPhase = int(inputPhase)
|
| 34 |
-
if inputPhase not in range(len(inputPhases)):
|
| 35 |
-
print("\n", inputPhase, "is not a valid option")
|
| 36 |
-
inputPhase = None
|
| 37 |
-
else:
|
| 38 |
-
return inputPhases[inputPhase]
|
| 39 |
-
else:
|
| 40 |
-
inputPhase = inputPhase.lower()
|
| 41 |
-
if inputPhase not in phases:
|
| 42 |
-
print("\n", inputPhase, "is not a valid option")
|
| 43 |
-
inputPhase = None
|
| 44 |
-
else:
|
| 45 |
-
return inputPhases[inputPhase]
|
| 46 |
-
|
| 47 |
-
print("Something went wrong, please consult the maintainer of the codebase.")
|
| 48 |
-
return inputPhase
|
| 49 |
|
| 50 |
# Function to validate if a directory exists
|
| 51 |
def validate_directory(directory_path):
|
|
@@ -169,13 +142,26 @@ def validate_and_run(phase, root_dir, templates_dir):
|
|
| 169 |
|
| 170 |
return run_steps(phase, root_dir, templates_dir)
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
# Gradio app components
|
| 173 |
with gr.Blocks() as app:
|
| 174 |
gr.Markdown("# Folder Creation Tool")
|
| 175 |
|
| 176 |
phase_input = gr.Dropdown(choices=list(inputPhases.values()), label="Select Phase")
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
create_button = gr.Button("Create Folders")
|
| 181 |
output = gr.Textbox(label="Output")
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
+
from shutil import copy
|
|
|
|
| 5 |
from tkinter import Tk
|
| 6 |
from tkinter.filedialog import askdirectory
|
| 7 |
+
from os import makedirs, listdir
|
| 8 |
+
from os.path import isdir, isfile, join, realpath
|
| 9 |
|
| 10 |
# --- Constants ---
|
| 11 |
phases = ["iFAT", "(i)SAT"]
|
| 12 |
inputPhases = {**{i: k for i, k in enumerate(phases)}, **{len(phases): "All"}}
|
|
|
|
| 13 |
regTemplate = r'template'
|
| 14 |
|
| 15 |
# --- Helper Functions ---
|
| 16 |
|
| 17 |
+
# Function to open a folder selection dialog
|
| 18 |
+
def select_folder():
|
| 19 |
+
Tk().withdraw() # Hides the root window
|
| 20 |
+
folder_selected = askdirectory()
|
| 21 |
+
return folder_selected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Function to validate if a directory exists
|
| 24 |
def validate_directory(directory_path):
|
|
|
|
| 142 |
|
| 143 |
return run_steps(phase, root_dir, templates_dir)
|
| 144 |
|
| 145 |
+
# Functions to trigger folder selection for Gradio
|
| 146 |
+
def select_root_directory():
|
| 147 |
+
return select_folder()
|
| 148 |
+
|
| 149 |
+
def select_templates_directory():
|
| 150 |
+
return select_folder()
|
| 151 |
+
|
| 152 |
# Gradio app components
|
| 153 |
with gr.Blocks() as app:
|
| 154 |
gr.Markdown("# Folder Creation Tool")
|
| 155 |
|
| 156 |
phase_input = gr.Dropdown(choices=list(inputPhases.values()), label="Select Phase")
|
| 157 |
+
|
| 158 |
+
root_dir_input = gr.Textbox(label="Root Directory", placeholder="Select the root directory")
|
| 159 |
+
root_dir_button = gr.Button("Select Root Directory")
|
| 160 |
+
root_dir_button.click(fn=select_root_directory, outputs=root_dir_input)
|
| 161 |
+
|
| 162 |
+
templates_dir_input = gr.Textbox(label="Templates Directory", placeholder="Select the templates directory")
|
| 163 |
+
templates_dir_button = gr.Button("Select Templates Directory")
|
| 164 |
+
templates_dir_button.click(fn=select_templates_directory, outputs=templates_dir_input)
|
| 165 |
|
| 166 |
create_button = gr.Button("Create Folders")
|
| 167 |
output = gr.Textbox(label="Output")
|