Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,17 +16,30 @@ def load_excel_sheets(file_path):
|
|
| 16 |
|
| 17 |
return sheets
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Function to create the combined prompt from selected values
|
| 20 |
-
def combine_selected_items(selected_items):
|
| 21 |
# Combine all the selected items into a single prompt
|
| 22 |
combined_prompt = " | ".join([item for item in selected_items if item])
|
| 23 |
return f"Combined Prompt: {combined_prompt}"
|
| 24 |
|
| 25 |
# Function to create the Gradio interface
|
| 26 |
-
def prompt_generator_interface(file_path):
|
| 27 |
# Load all the sheets and extract data from the first column
|
| 28 |
sheets = load_excel_sheets(file_path)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Gradio interface
|
| 31 |
with gr.Blocks() as interface:
|
| 32 |
gr.Markdown("# 📝 Witness Prompt Generator\nSelect an item from each sheet to generate a combined prompt.")
|
|
@@ -34,13 +47,10 @@ def prompt_generator_interface(file_path):
|
|
| 34 |
# Initialize an empty list to store all the dropdowns and user selections
|
| 35 |
dropdowns = []
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
reversed_sheet_names = list(sheets.keys())[::-1]
|
| 39 |
-
|
| 40 |
-
# Display all sheets as dropdowns in a grid
|
| 41 |
with gr.Row():
|
| 42 |
-
for sheet_name in
|
| 43 |
-
dropdown = gr.Dropdown(choices=
|
| 44 |
dropdowns.append(dropdown)
|
| 45 |
|
| 46 |
# Button to submit the combined prompt
|
|
@@ -59,6 +69,9 @@ if __name__ == "__main__":
|
|
| 59 |
# Path to your Excel file (adjust the path if necessary)
|
| 60 |
file_path = 'Witness Prompt Generator.xlsm'
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
# Create and launch interface
|
| 63 |
-
interface = prompt_generator_interface(file_path)
|
| 64 |
interface.launch()
|
|
|
|
| 16 |
|
| 17 |
return sheets
|
| 18 |
|
| 19 |
+
# Function to get the order of sheets from the main sheet
|
| 20 |
+
def get_sheet_order(file_path, main_sheet_name):
|
| 21 |
+
# Read the main sheet which contains the sheet order
|
| 22 |
+
df_order = pd.read_excel(file_path, sheet_name=main_sheet_name)
|
| 23 |
+
# Assuming the sheet names are listed in the first column
|
| 24 |
+
return df_order.iloc[:, 0].dropna().tolist()
|
| 25 |
+
|
| 26 |
# Function to create the combined prompt from selected values
|
| 27 |
+
def combine_selected_items(*selected_items):
|
| 28 |
# Combine all the selected items into a single prompt
|
| 29 |
combined_prompt = " | ".join([item for item in selected_items if item])
|
| 30 |
return f"Combined Prompt: {combined_prompt}"
|
| 31 |
|
| 32 |
# Function to create the Gradio interface
|
| 33 |
+
def prompt_generator_interface(file_path, main_sheet_name):
|
| 34 |
# Load all the sheets and extract data from the first column
|
| 35 |
sheets = load_excel_sheets(file_path)
|
| 36 |
|
| 37 |
+
# Get the sheet order from the main sheet
|
| 38 |
+
sheet_order = get_sheet_order(file_path, main_sheet_name)
|
| 39 |
+
|
| 40 |
+
# Filter out sheets that don't exist in the main order
|
| 41 |
+
valid_sheets = {sheet_name: sheets[sheet_name] for sheet_name in sheet_order if sheet_name in sheets}
|
| 42 |
+
|
| 43 |
# Gradio interface
|
| 44 |
with gr.Blocks() as interface:
|
| 45 |
gr.Markdown("# 📝 Witness Prompt Generator\nSelect an item from each sheet to generate a combined prompt.")
|
|
|
|
| 47 |
# Initialize an empty list to store all the dropdowns and user selections
|
| 48 |
dropdowns = []
|
| 49 |
|
| 50 |
+
# Display all sheets as dropdowns in the order specified by the main sheet
|
|
|
|
|
|
|
|
|
|
| 51 |
with gr.Row():
|
| 52 |
+
for sheet_name in valid_sheets:
|
| 53 |
+
dropdown = gr.Dropdown(choices=valid_sheets[sheet_name], label=sheet_name, interactive=True)
|
| 54 |
dropdowns.append(dropdown)
|
| 55 |
|
| 56 |
# Button to submit the combined prompt
|
|
|
|
| 69 |
# Path to your Excel file (adjust the path if necessary)
|
| 70 |
file_path = 'Witness Prompt Generator.xlsm'
|
| 71 |
|
| 72 |
+
# Define the name of the main sheet that contains the order of sheets
|
| 73 |
+
main_sheet_name = 'Main Order' # Change this to match the name of your control sheet
|
| 74 |
+
|
| 75 |
# Create and launch interface
|
| 76 |
+
interface = prompt_generator_interface(file_path, main_sheet_name)
|
| 77 |
interface.launch()
|