artificialguybr commited on
Commit
8669462
1 Parent(s): 66bd20d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -17,36 +17,40 @@ def query(payload, api_url, token):
17
 
18
  # Define the function to run when the button is clicked
19
  def run_lora(prompt):
20
- selected_lora = loras[0] # You can change this to select a different LoRA if needed
21
  api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
22
  trigger_word = selected_lora["trigger_word"]
23
- token = os.getenv("API_TOKEN") # Make sure you have set your API token
24
  payload = {"inputs": f"{prompt} {trigger_word}"}
25
  image_bytes = query(payload, api_url, token)
26
- return Image.open(image_bytes)
27
 
28
  # Gradio UI
29
  print("Before Gradio Interface")
30
 
31
  with gr.Blocks() as app:
 
 
 
 
 
 
 
 
 
 
32
  with gr.Row():
33
  with gr.Column():
34
- title = gr.HTML("<h1>LoRA the Explorer</h1>")
35
- gallery = gr.Gallery(
36
- [(item["image"], item["title"]) for item in loras],
37
- label="LoRA Gallery",
38
- allow_preview=False,
39
- columns=1, # Change to 1 column to make images smaller
40
- item_size=(150, 150) # Set the size of the gallery images
41
- )
42
  with gr.Column():
43
- prompt = gr.Textbox(label="Prompt", lines=1, max_lines=1, placeholder="Type a prompt after selecting a LoRA")
44
  gr.Button("Run").click(
45
  fn=run_lora,
46
  inputs=[prompt],
47
  outputs=[result]
48
  )
49
- result = gr.Image(interactive=False, label="Generated Image")
50
 
51
  print("After Gradio Interface")
52
 
 
17
 
18
  # Define the function to run when the button is clicked
19
  def run_lora(prompt):
20
+ selected_lora = loras[0]
21
  api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
22
  trigger_word = selected_lora["trigger_word"]
23
+ token = os.getenv("API_TOKEN")
24
  payload = {"inputs": f"{prompt} {trigger_word}"}
25
  image_bytes = query(payload, api_url, token)
26
+ return Image.open(image_bytes).resize((300, 300)) # Resizing the image
27
 
28
  # Gradio UI
29
  print("Before Gradio Interface")
30
 
31
  with gr.Blocks() as app:
32
+ title = gr.HTML("<h1>LoRA the Explorer</h1>")
33
+ gallery = gr.Gallery(
34
+ [(item["image"], item["title"]) for item in loras],
35
+ label="LoRA Gallery",
36
+ allow_preview=False,
37
+ columns=3,
38
+ )
39
+ prompt = gr.Textbox(label="Prompt", lines=1, max_lines=1, placeholder="Type a prompt after selecting a LoRA")
40
+ result = gr.Image(interactive=False, label="Generated Image")
41
+
42
  with gr.Row():
43
  with gr.Column():
44
+ title
45
+ gallery
 
 
 
 
 
 
46
  with gr.Column():
47
+ prompt
48
  gr.Button("Run").click(
49
  fn=run_lora,
50
  inputs=[prompt],
51
  outputs=[result]
52
  )
53
+ result
54
 
55
  print("After Gradio Interface")
56