artificialguybr commited on
Commit
1b088a5
1 Parent(s): a200bb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
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
- selected_lora = loras[selected_lora_index]
26
- api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
27
- trigger_word = selected_lora["trigger_word"]
28
- token = os.getenv("API_TOKEN")
29
- payload = {"inputs": f"{prompt} {trigger_word}"}
30
- image_bytes = query(payload, api_url, token)
31
- if image_bytes:
32
- return Image.open(image_bytes)
33
- else:
34
- return "API Error"
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") # Added "Run" button
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(