Spaces:
Runtime error
Runtime error
gpravin1308
commited on
Upload 3 files
Browse files- .gitattributes +1 -0
- Witness Prompt Generator.xlsm +3 -0
- app.py +48 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
Witness[[:space:]]Prompt[[:space:]]Generator.xlsm filter=lfs diff=lfs merge=lfs -text
|
Witness Prompt Generator.xlsm
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a845d79271bd6e15e22dd449924ad0bd76ef3c5f7cfd03d8646cc90fc2d787bd
|
3 |
+
size 2633479
|
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
8 |
+
# Load all sheets into a dictionary {sheet_name: DataFrame}
|
9 |
+
xls = pd.ExcelFile(file_path)
|
10 |
+
sheets = {sheet_name: pd.read_excel(xls, sheet_name=sheet_name).iloc[:, 0].dropna().tolist()
|
11 |
+
for sheet_name in xls.sheet_names}
|
12 |
+
return sheets
|
13 |
+
|
14 |
+
# Function to generate a random item from the selected sheet
|
15 |
+
def generate_random_item(sheet_name, sheets):
|
16 |
+
items = sheets.get(sheet_name, [])
|
17 |
+
if items:
|
18 |
+
return random.choice(items)
|
19 |
+
return "No items available."
|
20 |
+
|
21 |
+
# Gradio interface
|
22 |
+
def prompt_generator_interface(file_path):
|
23 |
+
# Load all the sheets and extract data from first column
|
24 |
+
sheets = load_excel_sheets(file_path)
|
25 |
+
|
26 |
+
# Define function for Gradio
|
27 |
+
def generate_prompt(sheet_name):
|
28 |
+
return generate_random_item(sheet_name, sheets)
|
29 |
+
|
30 |
+
# Create Gradio interface
|
31 |
+
interface = gr.Interface(
|
32 |
+
fn=generate_prompt, # Function to call for generating random item
|
33 |
+
inputs=gr.inputs.Dropdown(choices=list(sheets.keys()), label="Select Sheet"), # Dropdown to select sheet
|
34 |
+
outputs="text", # Output is a text
|
35 |
+
title="Excel Sheet Prompt Generator",
|
36 |
+
description="Select a sheet and generate a random item from that sheet"
|
37 |
+
)
|
38 |
+
|
39 |
+
return interface
|
40 |
+
|
41 |
+
# Create and launch the Gradio interface
|
42 |
+
if __name__ == "__main__":
|
43 |
+
# Path to your Excel file (adjust if needed)
|
44 |
+
file_path = 'Witness Prompt Generator.xlsm'
|
45 |
+
|
46 |
+
# Create and launch interface
|
47 |
+
interface = prompt_generator_interface(file_path)
|
48 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
gradio==2.2.15
|
3 |
+
openpyxl
|