Spaces:
Running
on
Zero
Running
on
Zero
Update feifeiui/feifeiui.py
Browse files- feifeiui/feifeiui.py +169 -153
feifeiui/feifeiui.py
CHANGED
@@ -1,153 +1,169 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import config
|
4 |
-
|
5 |
-
from feifeilib.feifeichat import feifeichat
|
6 |
-
from feifeilib.feifeitexttoimg import feifeitexttoimg
|
7 |
-
from feifeilib.feifeiflorence import feifeiflorence
|
8 |
-
|
9 |
-
MAX_SEED = np.iinfo(np.int32).max
|
10 |
-
MAX_IMAGE_SIZE = 4096
|
11 |
-
|
12 |
-
css = """
|
13 |
-
#col-container {
|
14 |
-
width: auto;
|
15 |
-
height: 750px;
|
16 |
-
}
|
17 |
-
"""
|
18 |
-
|
19 |
-
|
20 |
-
def create_ui():
|
21 |
-
with gr.Blocks(css=css) as FeiFei:
|
22 |
-
with gr.Row():
|
23 |
-
with gr.Column(scale=1):
|
24 |
-
with gr.Tab("Generator"):
|
25 |
-
prompt = gr.Text(
|
26 |
-
label="Prompt",
|
27 |
-
show_label=False,
|
28 |
-
placeholder="Enter your prompt",
|
29 |
-
max_lines=12,
|
30 |
-
container=False,
|
31 |
-
)
|
32 |
-
run_button = gr.Button("Run")
|
33 |
-
result = gr.Image(label="Result",
|
34 |
-
show_label=False,
|
35 |
-
interactive=False)
|
36 |
-
|
37 |
-
with gr.Accordion("Advanced Settings", open=False):
|
38 |
-
seed = gr.Slider(
|
39 |
-
label="Seed",
|
40 |
-
minimum=0,
|
41 |
-
maximum=MAX_SEED,
|
42 |
-
step=1,
|
43 |
-
value=0,
|
44 |
-
)
|
45 |
-
|
46 |
-
randomize_seed = gr.Checkbox(label="Randomize seed",
|
47 |
-
value=True)
|
48 |
-
|
49 |
-
with gr.Row():
|
50 |
-
width = gr.Slider(
|
51 |
-
label="Width",
|
52 |
-
minimum=256,
|
53 |
-
maximum=MAX_IMAGE_SIZE,
|
54 |
-
step=64,
|
55 |
-
value=896,
|
56 |
-
)
|
57 |
-
|
58 |
-
height = gr.Slider(
|
59 |
-
label="Height",
|
60 |
-
minimum=256,
|
61 |
-
maximum=MAX_IMAGE_SIZE,
|
62 |
-
step=64,
|
63 |
-
value=1152,
|
64 |
-
)
|
65 |
-
|
66 |
-
with gr.Row():
|
67 |
-
num_inference_steps = gr.Slider(
|
68 |
-
label="Number of inference steps",
|
69 |
-
minimum=1,
|
70 |
-
maximum=50,
|
71 |
-
step=1,
|
72 |
-
value=4,
|
73 |
-
)
|
74 |
-
guidancescale = gr.Slider(
|
75 |
-
label="Guidance scale",
|
76 |
-
minimum=0,
|
77 |
-
maximum=10,
|
78 |
-
step=0.1,
|
79 |
-
value=3.5,
|
80 |
-
)
|
81 |
-
num_strength = gr.Slider(
|
82 |
-
label="strength",
|
83 |
-
minimum=0,
|
84 |
-
maximum=2,
|
85 |
-
step=0.01,
|
86 |
-
value=0.35,
|
87 |
-
)
|
88 |
-
|
89 |
-
with gr.Tab("Styles"):
|
90 |
-
quality_select = gr.Checkbox(label="high quality")
|
91 |
-
sharpened_select = gr.Checkbox(label="Sharpened")
|
92 |
-
FooocusExpansion_select = gr.Checkbox(
|
93 |
-
label="FooocusExpansion")
|
94 |
-
styles_name = [
|
95 |
-
style["name"] for style in config.style_list
|
96 |
-
]
|
97 |
-
styles_Radio = gr.Dropdown(styles_name,
|
98 |
-
label="Styles",
|
99 |
-
multiselect=True)
|
100 |
-
with gr.Tab("Florence-2"):
|
101 |
-
|
102 |
-
input_img = gr.Image(label="Input Picture",
|
103 |
-
show_label=False)
|
104 |
-
|
105 |
-
florence_btn = gr.Button(value="Florence")
|
106 |
-
|
107 |
-
output_text = gr.Textbox(label="Output Text",
|
108 |
-
max_lines=12,
|
109 |
-
show_label=False,
|
110 |
-
container=False)
|
111 |
-
output_size = gr.Textbox(label="Output size",
|
112 |
-
max_lines=2,
|
113 |
-
show_label=False,
|
114 |
-
container=False)
|
115 |
-
output_img = gr.Image(label="Input Picture",
|
116 |
-
interactive=False,
|
117 |
-
show_label=False)
|
118 |
-
with gr.Column(scale=3, elem_id="col-container"):
|
119 |
-
gr.ChatInterface(
|
120 |
-
feifeichat,
|
121 |
-
type="messages",
|
122 |
-
multimodal=True,
|
123 |
-
additional_inputs=[
|
124 |
-
gr.Checkbox(label="Feifei"),
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import config
|
4 |
+
|
5 |
+
from feifeilib.feifeichat import feifeichat
|
6 |
+
from feifeilib.feifeitexttoimg import feifeitexttoimg
|
7 |
+
from feifeilib.feifeiflorence import feifeiflorence
|
8 |
+
|
9 |
+
MAX_SEED = np.iinfo(np.int32).max
|
10 |
+
MAX_IMAGE_SIZE = 4096
|
11 |
+
|
12 |
+
css = """
|
13 |
+
#col-container {
|
14 |
+
width: auto;
|
15 |
+
height: 750px;
|
16 |
+
}
|
17 |
+
"""
|
18 |
+
|
19 |
+
|
20 |
+
def create_ui():
|
21 |
+
with gr.Blocks(css=css) as FeiFei:
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column(scale=1):
|
24 |
+
with gr.Tab("Generator"):
|
25 |
+
prompt = gr.Text(
|
26 |
+
label="Prompt",
|
27 |
+
show_label=False,
|
28 |
+
placeholder="Enter your prompt",
|
29 |
+
max_lines=12,
|
30 |
+
container=False,
|
31 |
+
)
|
32 |
+
run_button = gr.Button("Run")
|
33 |
+
result = gr.Image(label="Result",
|
34 |
+
show_label=False,
|
35 |
+
interactive=False)
|
36 |
+
|
37 |
+
with gr.Accordion("Advanced Settings", open=False):
|
38 |
+
seed = gr.Slider(
|
39 |
+
label="Seed",
|
40 |
+
minimum=0,
|
41 |
+
maximum=MAX_SEED,
|
42 |
+
step=1,
|
43 |
+
value=0,
|
44 |
+
)
|
45 |
+
|
46 |
+
randomize_seed = gr.Checkbox(label="Randomize seed",
|
47 |
+
value=True)
|
48 |
+
|
49 |
+
with gr.Row():
|
50 |
+
width = gr.Slider(
|
51 |
+
label="Width",
|
52 |
+
minimum=256,
|
53 |
+
maximum=MAX_IMAGE_SIZE,
|
54 |
+
step=64,
|
55 |
+
value=896,
|
56 |
+
)
|
57 |
+
|
58 |
+
height = gr.Slider(
|
59 |
+
label="Height",
|
60 |
+
minimum=256,
|
61 |
+
maximum=MAX_IMAGE_SIZE,
|
62 |
+
step=64,
|
63 |
+
value=1152,
|
64 |
+
)
|
65 |
+
|
66 |
+
with gr.Row():
|
67 |
+
num_inference_steps = gr.Slider(
|
68 |
+
label="Number of inference steps",
|
69 |
+
minimum=1,
|
70 |
+
maximum=50,
|
71 |
+
step=1,
|
72 |
+
value=4,
|
73 |
+
)
|
74 |
+
guidancescale = gr.Slider(
|
75 |
+
label="Guidance scale",
|
76 |
+
minimum=0,
|
77 |
+
maximum=10,
|
78 |
+
step=0.1,
|
79 |
+
value=3.5,
|
80 |
+
)
|
81 |
+
num_strength = gr.Slider(
|
82 |
+
label="strength",
|
83 |
+
minimum=0,
|
84 |
+
maximum=2,
|
85 |
+
step=0.01,
|
86 |
+
value=0.35,
|
87 |
+
)
|
88 |
+
|
89 |
+
with gr.Tab("Styles"):
|
90 |
+
quality_select = gr.Checkbox(label="high quality")
|
91 |
+
sharpened_select = gr.Checkbox(label="Sharpened")
|
92 |
+
FooocusExpansion_select = gr.Checkbox(
|
93 |
+
label="FooocusExpansion")
|
94 |
+
styles_name = [
|
95 |
+
style["name"] for style in config.style_list
|
96 |
+
]
|
97 |
+
styles_Radio = gr.Dropdown(styles_name,
|
98 |
+
label="Styles",
|
99 |
+
multiselect=True)
|
100 |
+
with gr.Tab("Florence-2"):
|
101 |
+
|
102 |
+
input_img = gr.Image(label="Input Picture",
|
103 |
+
show_label=False)
|
104 |
+
|
105 |
+
florence_btn = gr.Button(value="Florence")
|
106 |
+
|
107 |
+
output_text = gr.Textbox(label="Output Text",
|
108 |
+
max_lines=12,
|
109 |
+
show_label=False,
|
110 |
+
container=False)
|
111 |
+
output_size = gr.Textbox(label="Output size",
|
112 |
+
max_lines=2,
|
113 |
+
show_label=False,
|
114 |
+
container=False)
|
115 |
+
output_img = gr.Image(label="Input Picture",
|
116 |
+
interactive=False,
|
117 |
+
show_label=False)
|
118 |
+
with gr.Column(scale=3, elem_id="col-container"):
|
119 |
+
gr.ChatInterface(
|
120 |
+
feifeichat,
|
121 |
+
type="messages",
|
122 |
+
multimodal=True,
|
123 |
+
additional_inputs=[
|
124 |
+
gr.Checkbox(label="Feifei"),
|
125 |
+
gr.Dropdown(
|
126 |
+
["meta-llama/Meta-Llama-3.1-70B-Instruct",
|
127 |
+
"CohereForAI/c4ai-command-r-plus-08-2024",
|
128 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
129 |
+
"nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
|
130 |
+
"NousResearch/Hermes-3-Llama-3.1-8B",
|
131 |
+
"mistralai/Mistral-Nemo-Instruct-2411",
|
132 |
+
"microsoft/Phi-3.5-mini-instruct"],
|
133 |
+
value="meta-llama/Meta-Llama-3.1-70B-Instruct",
|
134 |
+
show_label=False,
|
135 |
+
container=False),
|
136 |
+
gr.Radio(
|
137 |
+
["pixtral","Vsiion"],
|
138 |
+
value="Vsiion",
|
139 |
+
show_label=False,
|
140 |
+
container=False)
|
141 |
+
],
|
142 |
+
)
|
143 |
+
|
144 |
+
run_button.click(
|
145 |
+
fn=feifeitexttoimg, # Function to run for this button
|
146 |
+
inputs=[
|
147 |
+
prompt,
|
148 |
+
quality_select,
|
149 |
+
sharpened_select,
|
150 |
+
styles_Radio,
|
151 |
+
FooocusExpansion_select,
|
152 |
+
seed,
|
153 |
+
randomize_seed,
|
154 |
+
width,
|
155 |
+
height,
|
156 |
+
num_inference_steps,
|
157 |
+
guidancescale,
|
158 |
+
num_strength,
|
159 |
+
],
|
160 |
+
outputs=[result, seed],
|
161 |
+
)
|
162 |
+
|
163 |
+
florence_btn.click(
|
164 |
+
fn=feifeiflorence, # Function to run when the button is clicked
|
165 |
+
inputs=[input_img], # Input components for the function
|
166 |
+
outputs=[output_text, output_size,
|
167 |
+
output_img], # Output component for the function
|
168 |
+
)
|
169 |
+
return FeiFei
|