File size: 2,334 Bytes
a996c52 |
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 |
import gradio as gr
import os
from utils.steps import *
# Global variables to store inputs
testphase = None
rootDir = None
templatesDir = None
# Function to validate directory existence
def validate_directory(directory_path):
if os.path.isdir(directory_path):
return True
else:
return False
# Improved createFolders function with error handling and feedback
def createFolders():
global rootDir, testphase, templatesDir
if not rootDir:
return "Error: Root directory not provided."
if not templatesDir:
return "Error: Templates directory not provided."
if not testphase:
return "Error: Phase not selected."
# Check if directories exist
if not validate_directory(rootDir):
return f"Error: Root directory '{rootDir}' does not exist."
if not validate_directory(templatesDir):
return f"Error: Templates directory '{templatesDir}' does not exist."
# Proceed with folder creation if all inputs are valid
copyPasteTemplates(rootDir, testphase, templatesDir)
return "Folders created successfully!"
# Main function to run steps
def run_steps(phase, root_dir, templates_dir):
global testphase, rootDir, templatesDir
testphase = phase
rootDir = root_dir
templatesDir = templates_dir
# Run folder creation process
result = createFolders()
return result
# Gradio interface
def validate_and_run(phase, root_dir, templates_dir):
# Check for empty inputs
if not root_dir or not templates_dir:
return "Error: Please provide both the root and templates directory paths."
# Run the main function with inputs
return run_steps(phase, root_dir, templates_dir)
# Gradio app components
with gr.Blocks() as app:
gr.Markdown("# Folder Creation Tool")
phase_input = gr.Dropdown(choices=inputPhases.values(), label="Select Phase")
root_dir_input = gr.Textbox(label="Root Directory", placeholder="Enter the root directory path")
templates_dir_input = gr.Textbox(label="Templates Directory", placeholder="Enter the templates directory path")
create_button = gr.Button("Create Folders")
output = gr.Textbox(label="Output")
create_button.click(validate_and_run, inputs=[phase_input, root_dir_input, templates_dir_input], outputs=output)
app.launch()
|