Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
-
# 1. Import necessary libraries
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
-
import random
|
5 |
|
6 |
# Function to load Excel sheets and extract first column data from valid sheets
|
7 |
def load_excel_sheets(file_path):
|
@@ -13,42 +11,47 @@ def load_excel_sheets(file_path):
|
|
13 |
df = pd.read_excel(xls, sheet_name=sheet_name)
|
14 |
# Check if the sheet has at least one column and is not empty
|
15 |
if not df.empty and df.shape[1] > 0:
|
16 |
-
# Extract the first column and
|
17 |
sheets[sheet_name] = df.iloc[:, 0].dropna().tolist()
|
18 |
-
else:
|
19 |
-
# If the sheet is empty or has no valid data, skip it
|
20 |
-
sheets[sheet_name] = [] # Optional: You can skip or keep an empty list
|
21 |
|
22 |
return sheets
|
23 |
|
24 |
-
# Function to
|
25 |
-
def
|
26 |
-
items
|
27 |
-
if
|
28 |
-
|
29 |
-
return "No items available."
|
30 |
|
31 |
-
# Gradio interface
|
32 |
def prompt_generator_interface(file_path):
|
33 |
# Load all the sheets and extract data from the first column
|
34 |
sheets = load_excel_sheets(file_path)
|
35 |
|
36 |
-
#
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
return interface
|
53 |
|
54 |
# Create and launch the Gradio interface
|
|
|
|
|
1 |
import pandas as pd
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
# Function to load Excel sheets and extract first column data from valid sheets
|
5 |
def load_excel_sheets(file_path):
|
|
|
11 |
df = pd.read_excel(xls, sheet_name=sheet_name)
|
12 |
# Check if the sheet has at least one column and is not empty
|
13 |
if not df.empty and df.shape[1] > 0:
|
14 |
+
# Extract the first column and keep the order intact
|
15 |
sheets[sheet_name] = df.iloc[:, 0].dropna().tolist()
|
|
|
|
|
|
|
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.")
|
33 |
+
|
34 |
+
# Initialize an empty list to store all the dropdowns and user selections
|
35 |
+
dropdowns = []
|
36 |
+
|
37 |
+
# Reverse the order of sheets to display them right to left
|
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 reversed_sheet_names:
|
43 |
+
dropdown = gr.Dropdown(choices=sheets[sheet_name], label=sheet_name, interactive=True)
|
44 |
+
dropdowns.append(dropdown)
|
45 |
+
|
46 |
+
# Button to submit the combined prompt
|
47 |
+
submit_button = gr.Button("Generate Combined Prompt")
|
48 |
+
|
49 |
+
# Textbox to display the combined prompt
|
50 |
+
combined_output = gr.Textbox(label="Combined Prompt", placeholder="Your combined prompt will appear here...")
|
51 |
+
|
52 |
+
# Action when the submit button is clicked
|
53 |
+
submit_button.click(combine_selected_items, inputs=dropdowns, outputs=combined_output)
|
54 |
+
|
55 |
return interface
|
56 |
|
57 |
# Create and launch the Gradio interface
|