Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
artificialguybr
commited on
Commit
•
1b088a5
1
Parent(s):
a200bb2
Update app.py
Browse files
app.py
CHANGED
@@ -22,20 +22,20 @@ def query(payload, api_url, token):
|
|
22 |
|
23 |
# Define the function to run when the button is clicked
|
24 |
def run_lora(prompt, selected_lora_index):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
# Placeholder for gallery.select function
|
37 |
def update_selection(selected):
|
38 |
-
return selected
|
39 |
|
40 |
# Gradio UI
|
41 |
with gr.Blocks(css="custom.css") as app:
|
@@ -52,7 +52,7 @@ with gr.Blocks(css="custom.css") as app:
|
|
52 |
prompt_title = gr.Markdown("### Click on a LoRA in the gallery to select it")
|
53 |
with gr.Row():
|
54 |
prompt = gr.Textbox(label="Prompt", show_label=False, lines=1, max_lines=1, placeholder="Type a prompt after selecting a LoRA")
|
55 |
-
button = gr.Button("Run")
|
56 |
result = gr.Image(interactive=False, label="Generated Image")
|
57 |
|
58 |
gallery.select(
|
|
|
22 |
|
23 |
# Define the function to run when the button is clicked
|
24 |
def run_lora(prompt, selected_lora_index):
|
25 |
+
if selected_lora_index is not None: # Check if selected_lora_index is not None
|
26 |
+
selected_lora = loras[selected_lora_index]
|
27 |
+
api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
|
28 |
+
trigger_word = selected_lora["trigger_word"]
|
29 |
+
token = os.getenv("API_TOKEN")
|
30 |
+
payload = {"inputs": f"{prompt} {trigger_word}"}
|
31 |
+
image_bytes = query(payload, api_url, token)
|
32 |
+
if image_bytes:
|
33 |
+
return Image.open(image_bytes)
|
34 |
+
return "API Error or No LoRA selected"
|
35 |
|
36 |
# Placeholder for gallery.select function
|
37 |
def update_selection(selected):
|
38 |
+
return selected, # Return as a tuple
|
39 |
|
40 |
# Gradio UI
|
41 |
with gr.Blocks(css="custom.css") as app:
|
|
|
52 |
prompt_title = gr.Markdown("### Click on a LoRA in the gallery to select it")
|
53 |
with gr.Row():
|
54 |
prompt = gr.Textbox(label="Prompt", show_label=False, lines=1, max_lines=1, placeholder="Type a prompt after selecting a LoRA")
|
55 |
+
button = gr.Button("Run")
|
56 |
result = gr.Image(interactive=False, label="Generated Image")
|
57 |
|
58 |
gallery.select(
|