PhotographerAlpha7's picture
Create app.py
d422e50 verified
raw
history blame
1.29 kB
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_promt
#Load categories from the JSON file
with open('categories.json', 'r') as file:
categories = json.load(file)
#Create interative choices with gradio
choices = {}
for category, options in categories.items():
choice = gr.Dropdown(list(["random", "none"] + options['random']), label=category, type="value")
choices[category] = choice
#Create result text
result_text = gr.Textbox(Generated Prompt())
iface = gr.Interface(
fn=None,
live=True,
inputs=[choice for choice in choices.values()],
outputs=[result_text],
)
iface.launch()