PhotographerAlpha7 commited on
Commit
243bb44
·
verified ·
1 Parent(s): bce1e95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -2,46 +2,53 @@ import json
2
  import random
3
  import gradio as gr
4
 
 
5
  def generate_prompt():
6
- generated_prompt =[]
7
  for category, values in choices.items():
8
  choice = values.get()
9
  selected_choice = choice
10
  prompt_part = generate_category_prompt(category, selected_choice)
11
  if prompt_part:
12
  generated_prompt.append(prompt_part)
13
- return ", ".join(generated_prompt)
 
14
 
15
  def generate_category_prompt(category, choice):
16
  if choice == 'random':
17
  word = random.choice(categories[category]['random'])
18
- #elif choice == 'none'
19
- #return None
20
- #else:
21
- #word = choice
22
- #return word
 
 
23
  def generate_prompt_interface():
24
  generated_prompt = generate_prompt()
25
- result_text.value = generated_promt
26
 
27
 
28
- #Load categories from the JSON file
29
  with open('categories.json', 'r') as file:
30
  categories = json.load(file)
31
 
32
- #Create interative choices with gradio
33
  choices = {}
34
 
35
  for category, options in categories.items():
36
- choice = gr.Dropdown(list(["random", "none"] + options['random']), label=category, type="value")
37
  choices[category] = choice
38
 
 
39
 
40
  iface = gr.Interface(
41
- fn=None,
42
- live=True,
43
- inputs=[choice for choice in choices.values()],
44
- outputs=[generate_prompt],
 
 
45
  )
46
 
47
  iface.launch()
 
2
  import random
3
  import gradio as gr
4
 
5
+
6
  def generate_prompt():
7
+ generated_prompt = []
8
  for category, values in choices.items():
9
  choice = values.get()
10
  selected_choice = choice
11
  prompt_part = generate_category_prompt(category, selected_choice)
12
  if prompt_part:
13
  generated_prompt.append(prompt_part)
14
+ return ", ".join(generated_prompt)
15
+
16
 
17
  def generate_category_prompt(category, choice):
18
  if choice == 'random':
19
  word = random.choice(categories[category]['random'])
20
+ elif choice == 'none':
21
+ return None
22
+ else:
23
+ word = choice
24
+ return word
25
+
26
+
27
  def generate_prompt_interface():
28
  generated_prompt = generate_prompt()
29
+ result_text.value = generated_prompt
30
 
31
 
32
+ # Load categories from the JSON file
33
  with open('categories.json', 'r') as file:
34
  categories = json.load(file)
35
 
36
+ # Create interactive choices with gradio
37
  choices = {}
38
 
39
  for category, options in categories.items():
40
+ choice = gr.inputs.Dropdown(list=["random", "none"] + options['random'], label=category, type="value")
41
  choices[category] = choice
42
 
43
+ result_text = gr.outputs.Textbox()
44
 
45
  iface = gr.Interface(
46
+ fn=generate_prompt_interface,
47
+ inputs=list(choices.values()),
48
+ outputs=result_text,
49
+ title="Prompt Generator",
50
+ description="Generate a prompt by selecting options from the dropdown menus.",
51
+ theme="compact"
52
  )
53
 
54
  iface.launch()