testfiles / app.py
dunlp's picture
Create app.py
a996c52 verified
raw
history blame
2.33 kB
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()