svjack commited on
Commit
a0a2137
1 Parent(s): 9837774

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -5,6 +5,14 @@ import random
5
  import os
6
  from PIL import Image
7
  from huggingface_hub import InferenceApi, InferenceClient
 
 
 
 
 
 
 
 
8
 
9
  def get_params(request: gr.Request):
10
  params = request.query_params
@@ -14,7 +22,7 @@ def get_params(request: gr.Request):
14
  client = InferenceClient()
15
  models = client.list_deployed_models()
16
  list_models = models["text-to-image"]
17
- return list_models
18
 
19
  client = InferenceClient()
20
  models = client.list_deployed_models()
@@ -232,20 +240,16 @@ with gr.Blocks(css=css) as demo:
232
  image_style = gr.Dropdown(label="Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="Portrait", allow_custom_value=False)
233
 
234
  with gr.Row():
235
- gr.Examples(
236
- [
237
- "Chinese ink painting",
238
- "silk road",
239
- "masterpiece, best quality, 1girl, solo, crop top, denim shorts, choker, (graffiti:1.5), paint splatter, arms behind back, against wall, looking at viewer, armband, thigh strap, paint on body, head tilt, bored, multicolored hair, aqua eyes, headset,",
240
- "beautiful home",
241
- "interior design of living room",
242
- "1girl, aqua eyes, baseball cap, blonde hair, closed mouth, earrings, green background, hat, hoop earrings, jewelry, looking at viewer, shirt, short hair, simple background, solo, upper body, yellow shirt",
243
- ],
244
- inputs = text_prompt,
245
- label = "Prompt Examples"
246
- )
247
 
248
  text_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
249
- demo.load(get_params, None, current_model)
250
 
251
  demo.launch(show_api=False)
 
5
  import os
6
  from PIL import Image
7
  from huggingface_hub import InferenceApi, InferenceClient
8
+ from datasets import load_dataset
9
+
10
+ dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
11
+ prompt_df = dataset["train"].to_pandas()
12
+
13
+ def get_samples():
14
+ prompt_list = prompt_df.sample(n = 10)["Prompt"].values.tolist()
15
+ return prompt_list
16
 
17
  def get_params(request: gr.Request):
18
  params = request.query_params
 
22
  client = InferenceClient()
23
  models = client.list_deployed_models()
24
  list_models = models["text-to-image"]
25
+ return list_models, get_samples()
26
 
27
  client = InferenceClient()
28
  models = client.list_deployed_models()
 
240
  image_style = gr.Dropdown(label="Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="Portrait", allow_custom_value=False)
241
 
242
  with gr.Row():
243
+ with gr.Columns():
244
+ exps = gr.Examples(
245
+ get_samples(),
246
+ inputs = text_prompt,
247
+ label = "Prompt Examples"
248
+ )
249
+ exp_refresh = gr.Button(value="Click Refresh to get newly prompt examples")
250
+ exp_refresh.click(get_samples, None, exps)
 
 
 
 
251
 
252
  text_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
253
+ demo.load(get_params, None, [current_model, exps])
254
 
255
  demo.launch(show_api=False)