Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from utils.steps import *
|
| 4 |
+
|
| 5 |
+
# Global variables to store inputs
|
| 6 |
+
testphase = None
|
| 7 |
+
rootDir = None
|
| 8 |
+
templatesDir = None
|
| 9 |
+
|
| 10 |
+
# Function to validate directory existence
|
| 11 |
+
def validate_directory(directory_path):
|
| 12 |
+
if os.path.isdir(directory_path):
|
| 13 |
+
return True
|
| 14 |
+
else:
|
| 15 |
+
return False
|
| 16 |
+
|
| 17 |
+
# Improved createFolders function with error handling and feedback
|
| 18 |
+
def createFolders():
|
| 19 |
+
global rootDir, testphase, templatesDir
|
| 20 |
+
if not rootDir:
|
| 21 |
+
return "Error: Root directory not provided."
|
| 22 |
+
if not templatesDir:
|
| 23 |
+
return "Error: Templates directory not provided."
|
| 24 |
+
if not testphase:
|
| 25 |
+
return "Error: Phase not selected."
|
| 26 |
+
|
| 27 |
+
# Check if directories exist
|
| 28 |
+
if not validate_directory(rootDir):
|
| 29 |
+
return f"Error: Root directory '{rootDir}' does not exist."
|
| 30 |
+
if not validate_directory(templatesDir):
|
| 31 |
+
return f"Error: Templates directory '{templatesDir}' does not exist."
|
| 32 |
+
|
| 33 |
+
# Proceed with folder creation if all inputs are valid
|
| 34 |
+
copyPasteTemplates(rootDir, testphase, templatesDir)
|
| 35 |
+
return "Folders created successfully!"
|
| 36 |
+
|
| 37 |
+
# Main function to run steps
|
| 38 |
+
def run_steps(phase, root_dir, templates_dir):
|
| 39 |
+
global testphase, rootDir, templatesDir
|
| 40 |
+
testphase = phase
|
| 41 |
+
rootDir = root_dir
|
| 42 |
+
templatesDir = templates_dir
|
| 43 |
+
|
| 44 |
+
# Run folder creation process
|
| 45 |
+
result = createFolders()
|
| 46 |
+
return result
|
| 47 |
+
|
| 48 |
+
# Gradio interface
|
| 49 |
+
def validate_and_run(phase, root_dir, templates_dir):
|
| 50 |
+
# Check for empty inputs
|
| 51 |
+
if not root_dir or not templates_dir:
|
| 52 |
+
return "Error: Please provide both the root and templates directory paths."
|
| 53 |
+
|
| 54 |
+
# Run the main function with inputs
|
| 55 |
+
return run_steps(phase, root_dir, templates_dir)
|
| 56 |
+
|
| 57 |
+
# Gradio app components
|
| 58 |
+
with gr.Blocks() as app:
|
| 59 |
+
gr.Markdown("# Folder Creation Tool")
|
| 60 |
+
|
| 61 |
+
phase_input = gr.Dropdown(choices=inputPhases.values(), label="Select Phase")
|
| 62 |
+
root_dir_input = gr.Textbox(label="Root Directory", placeholder="Enter the root directory path")
|
| 63 |
+
templates_dir_input = gr.Textbox(label="Templates Directory", placeholder="Enter the templates directory path")
|
| 64 |
+
|
| 65 |
+
create_button = gr.Button("Create Folders")
|
| 66 |
+
output = gr.Textbox(label="Output")
|
| 67 |
+
|
| 68 |
+
create_button.click(validate_and_run, inputs=[phase_input, root_dir_input, templates_dir_input], outputs=output)
|
| 69 |
+
|
| 70 |
+
app.launch()
|