File size: 1,253 Bytes
d422e50 243bb44 d422e50 243bb44 d422e50 243bb44 d422e50 243bb44 d422e50 243bb44 d422e50 243bb44 d422e50 243bb44 d422e50 b36701d d422e50 b36701d d422e50 243bb44 b36701d d422e50 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import json
import random
import gradio as gr
def generate_prompt():
generated_prompt = []
for category, values in choices.items():
choice = values.get()
selected_choice = choice
prompt_part = generate_category_prompt(category, selected_choice)
if prompt_part:
generated_prompt.append(prompt_part)
return ", ".join(generated_prompt)
def generate_category_prompt(category, choice):
if choice == 'random':
word = random.choice(categories[category]['random'])
elif choice == 'none':
return None
else:
word = choice
return word
def generate_prompt_interface():
generated_prompt = generate_prompt()
result_text.value = generated_prompt
# Load categories from the JSON file
with open('categories.json', 'r') as file:
categories = json.load(file)
# Create interactive choices with gradio
choices = {}
for category, options in categories.items():
choice = gr.Dropdown(choices=["random", "none"] + options['random'], label=category, type="value")
choices[category] = choice
result_text = gr.Textbox()
iface = gr.Interface(
fn=generate_prompt_interface,
inputs=list(choices.values()),
outputs=result_text
)
iface.launch() |