Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,20 @@ def select_model(model_name):
|
|
25 |
if model_name in MODEL_LIST:
|
26 |
return API_BASE_URL + model_name
|
27 |
|
28 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
model_url = select_model(selected_model)
|
30 |
API_URL = f"{model_url}"
|
31 |
|
@@ -63,7 +76,8 @@ with gr.Blocks(theme="soft") as playground:
|
|
63 |
with gr.Column(elem_id="prompt-container"):
|
64 |
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
|
65 |
model_dropdown = gr.Dropdown(label="Model", choices=MODEL_LIST, elem_id="model-dropdown", value="runwayml/stable-diffusion-v1-5")
|
66 |
-
|
|
|
67 |
|
68 |
with gr.Accordion("Advanced settings", open=False):
|
69 |
negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
|
@@ -77,6 +91,7 @@ with gr.Blocks(theme="soft") as playground:
|
|
77 |
"""
|
78 |
)
|
79 |
|
80 |
-
|
|
|
81 |
|
82 |
playground.launch(show_api=False)
|
|
|
25 |
if model_name in MODEL_LIST:
|
26 |
return API_BASE_URL + model_name
|
27 |
|
28 |
+
def extend_prompt(input_text):
|
29 |
+
API_URL = "https://api-inference.huggingface.co/models/Gustavosta/MagicPrompt-Stable-Diffusion"
|
30 |
+
|
31 |
+
payload = {
|
32 |
+
"inputs": input_text
|
33 |
+
}
|
34 |
+
|
35 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
36 |
+
response.raise_for_status()
|
37 |
+
|
38 |
+
extended_prompt = response.content
|
39 |
+
return extended_prompt
|
40 |
+
|
41 |
+
def generate_image(prompt, selected_model, is_negative=False, steps=1, cfg_scale=6, seed=None):
|
42 |
model_url = select_model(selected_model)
|
43 |
API_URL = f"{model_url}"
|
44 |
|
|
|
76 |
with gr.Column(elem_id="prompt-container"):
|
77 |
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
|
78 |
model_dropdown = gr.Dropdown(label="Model", choices=MODEL_LIST, elem_id="model-dropdown", value="runwayml/stable-diffusion-v1-5")
|
79 |
+
gen_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
80 |
+
extend_button = gr.Button("Extend Prompt", variant='primary', elem_id="extend-button")
|
81 |
|
82 |
with gr.Accordion("Advanced settings", open=False):
|
83 |
negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
|
|
|
91 |
"""
|
92 |
)
|
93 |
|
94 |
+
gen_button.click(generate_image, inputs=[text_prompt, model_dropdown, negative_prompt], outputs=image_output)
|
95 |
+
extend_button.click(extend_prompt, inputs=text_prompt, outputs=text_prompt)
|
96 |
|
97 |
playground.launch(show_api=False)
|