gpravin1308 commited on
Commit
016b0ba
·
verified ·
1 Parent(s): b137304

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -23,11 +23,15 @@ def get_sheet_order(file_path, 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):
@@ -36,22 +40,35 @@ def prompt_generator_interface(file_path, main_sheet_name):
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.")
46
 
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
57
  submit_button = gr.Button("Generate Combined Prompt")
@@ -60,7 +77,7 @@ def prompt_generator_interface(file_path, main_sheet_name):
60
  combined_output = gr.Textbox(label="Combined Prompt", placeholder="Your combined prompt will appear here...")
61
 
62
  # Action when the submit button is clicked
63
- submit_button.click(combine_selected_items, inputs=dropdowns, outputs=combined_output)
64
 
65
  return interface
66
 
 
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 and weights
27
+ def combine_selected_items(*selected_items_and_weights):
28
+ combined_prompt = []
29
+ for i in range(0, len(selected_items_and_weights), 2):
30
+ item = selected_items_and_weights[i]
31
+ weight = selected_items_and_weights[i+1]
32
+ if item:
33
+ combined_prompt.append(f"{item} (Weight: {weight})" if weight else item)
34
+ return f"Combined Prompt: {' | '.join(combined_prompt)}"
35
 
36
  # Function to create the Gradio interface
37
  def prompt_generator_interface(file_path, main_sheet_name):
 
40
 
41
  # Get the sheet order from the main sheet
42
  sheet_order = get_sheet_order(file_path, main_sheet_name)
43
+
44
  # Filter out sheets that don't exist in the main order
45
  valid_sheets = {sheet_name: sheets[sheet_name] for sheet_name in sheet_order if sheet_name in sheets}
46
 
47
+ # Define the sheets that should NOT have weights
48
+ no_weight_sheets = ["Poetic", "Scenarios", "Camera Setup", "Combos", "PositiceNegative prompts", "LAZY Mode"]
49
+
50
+ # Move Resources tab to the last place
51
+ if 'Resources' in valid_sheets:
52
+ valid_sheets['Resources'] = valid_sheets.pop('Resources')
53
+
54
  # Gradio interface
55
  with gr.Blocks() as interface:
56
  gr.Markdown("# 📝 Witness Prompt Generator\nSelect an item from each sheet to generate a combined prompt.")
57
 
58
+ # Initialize an empty list to store all the dropdowns and weight inputs
59
+ dropdowns_and_weights = []
60
+
61
  # Display all sheets as dropdowns in the order specified by the main sheet
62
  with gr.Row():
63
  for sheet_name in valid_sheets:
64
+ with gr.Column():
65
+ dropdown = gr.Dropdown(choices=valid_sheets[sheet_name], label=sheet_name, interactive=True)
66
+ dropdowns_and_weights.append(dropdown)
67
+
68
+ # If the sheet is not in the no_weight_sheets, add a weight input
69
+ if sheet_name not in no_weight_sheets:
70
+ weight_input = gr.Textbox(label=f"{sheet_name} Weight", placeholder="Enter weight (optional)", interactive=True)
71
+ dropdowns_and_weights.append(weight_input)
72
 
73
  # Button to submit the combined prompt
74
  submit_button = gr.Button("Generate Combined Prompt")
 
77
  combined_output = gr.Textbox(label="Combined Prompt", placeholder="Your combined prompt will appear here...")
78
 
79
  # Action when the submit button is clicked
80
+ submit_button.click(combine_selected_items, inputs=dropdowns_and_weights, outputs=combined_output)
81
 
82
  return interface
83