fffiloni commited on
Commit
0c86bfd
1 Parent(s): 645f208

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -58
app.py CHANGED
@@ -6,51 +6,8 @@ import os
6
 
7
  from utils.gradio_helpers import parse_outputs, process_outputs
8
 
9
- inputs = []
10
- inputs.append(gr.Textbox(
11
- label="Prompt", info='''Describe the subject. Include clothes and hairstyle for more consistency.'''
12
- ))
13
-
14
- inputs.append(gr.Textbox(
15
- label="Negative Prompt", info='''Things you do not want to see in your image'''
16
- ))
17
-
18
- inputs.append(gr.Image(
19
- label="Subject", type="filepath"
20
- ))
21
-
22
- inputs.append(gr.Slider(
23
- label="Number Of Outputs", info='''The number of images to generate.''', value=3,
24
- minimum=1, maximum=20, step=1,
25
- ))
26
-
27
- inputs.append(gr.Slider(
28
- label="Number Of Images Per Pose", info='''The number of images to generate for each pose.''', value=1,
29
- minimum=1, maximum=4, step=1,
30
- ))
31
-
32
- inputs.append(gr.Checkbox(
33
- label="Randomise Poses", info='''Randomise the poses used.''', value=True
34
- ))
35
-
36
- inputs.append(gr.Dropdown(
37
- choices=['webp', 'jpg', 'png'], label="output_format", info='''Format of the output images''', value="webp"
38
- ))
39
-
40
- inputs.append(gr.Number(
41
- label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=80
42
- ))
43
-
44
- inputs.append(gr.Number(
45
- label="Seed", info='''Set a seed for reproducibility. Random by default.''', value=None
46
- ))
47
-
48
  names = ['prompt', 'negative_prompt', 'subject', 'number_of_outputs', 'number_of_images_per_pose', 'randomise_poses', 'output_format', 'output_quality', 'seed']
49
 
50
- outputs = []
51
- outputs.append(gr.Gallery())
52
-
53
- expected_outputs = len(outputs)
54
  def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
55
  headers = {'Content-Type': 'application/json'}
56
 
@@ -82,10 +39,7 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
82
  if(outputs[0].get_config()["name"] == "json"):
83
  return json_response["output"]
84
  predict_outputs = parse_outputs(json_response["output"])
85
- processed_outputs = process_outputs(predict_outputs)
86
- difference_outputs = expected_outputs - len(processed_outputs)
87
-
88
-
89
  return tuple(processed_outputs) if len(processed_outputs) > 1 else processed_outputs[0]
90
  else:
91
  if(response.status_code == 409):
@@ -93,15 +47,63 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
93
  raise gr.Error(f"The submission failed! Error: {response.status_code}")
94
 
95
  title = "Demo for consistent-character cog image by fofr"
96
- model_description = "Create images of a given character in different poses"
97
-
98
- app = gr.Interface(
99
- fn=predict,
100
- inputs=inputs,
101
- outputs=outputs,
102
- title=title,
103
- description=model_description,
104
- allow_flagging="never",
105
- )
106
- app.launch(share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
 
6
 
7
  from utils.gradio_helpers import parse_outputs, process_outputs
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  names = ['prompt', 'negative_prompt', 'subject', 'number_of_outputs', 'number_of_images_per_pose', 'randomise_poses', 'output_format', 'output_quality', 'seed']
10
 
 
 
 
 
11
  def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
12
  headers = {'Content-Type': 'application/json'}
13
 
 
39
  if(outputs[0].get_config()["name"] == "json"):
40
  return json_response["output"]
41
  predict_outputs = parse_outputs(json_response["output"])
42
+ processed_outputs = process_outputs(predict_outputs)
 
 
 
43
  return tuple(processed_outputs) if len(processed_outputs) > 1 else processed_outputs[0]
44
  else:
45
  if(response.status_code == 409):
 
47
  raise gr.Error(f"The submission failed! Error: {response.status_code}")
48
 
49
  title = "Demo for consistent-character cog image by fofr"
50
+ model_description = "Create images of a given character in different poses • running cog image by fofr"
51
+
52
+ with gr.Blocks() as app:
53
+ with gr.Column(elem_id="col-container"):
54
+ gr.HTML(f"""
55
+ <h2 style="text-align: center;">Consistent Character Workflow</h2>
56
+ <p style="text-align: center;">{description}</p>
57
+ """)
58
+
59
+ with gr.Row():
60
+ with gr.Column():
61
+ prompt = gr.Textbox(
62
+ label="Prompt", info='''Describe the subject. Include clothes and hairstyle for more consistency.'''
63
+ )
64
+
65
+ subject = gr.Image(
66
+ label="Subject", type="filepath"
67
+ )
68
+
69
+ submit_btn = gr.Button("Submit")
70
+
71
+ with gr.Accordion(label="Advanced Settings", open=false):
72
+ negative_prompt = gr.Textbox(
73
+ label="Negative Prompt", info='''Things you do not want to see in your image'''
74
+ )
75
+
76
+ number_of_outputs = gr.Slider(
77
+ label="Number Of Outputs", info='''The number of images to generate.''', value=3,
78
+ minimum=1, maximum=20, step=1,
79
+ )
80
+
81
+ number_of_images_per_pose = gr.Slider(
82
+ label="Number Of Images Per Pose", info='''The number of images to generate for each pose.''', value=1,
83
+ minimum=1, maximum=4, step=1,
84
+ )
85
+
86
+ randomise_poses = gr.Checkbox(
87
+ label="Randomise Poses", info='''Randomise the poses used.''', value=True
88
+ )
89
+
90
+ output_format = gr.Dropdown(
91
+ choices=['webp', 'jpg', 'png'], label="output_format", info='''Format of the output images''', value="webp"
92
+ )
93
+
94
+ output_quality = gr.Number(
95
+ label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=80
96
+ )
97
+
98
+ seed = gr.Number(
99
+ label="Seed", info='''Set a seed for reproducibility. Random by default.''', value=None
100
+ )
101
+
102
+ with gr.Column():
103
+ consistent_results = gr.Gallery(label="Consistent Results")
104
+
105
+ inputs = [prompt, negative_prompt, subject, number_of_outputs, number_of_images_per_pose, randomise_poses, output_format, output_quality, seed]
106
+ outputs = [consistent_results]
107
+
108
+ app.queue().launch(share=False)
109