artificialguybr commited on
Commit
538d554
1 Parent(s): c03b3ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -21
app.py CHANGED
@@ -17,22 +17,17 @@ def query(payload, api_url, token):
17
 
18
  # Define the function to run when the button is clicked
19
  def run_lora(prompt, weight):
20
- print("Inside run_lora")
21
- selected_lora = loras[0] # You may need to adjust this index if you have multiple models
22
  api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
23
  trigger_word = selected_lora["trigger_word"]
24
- token = os.getenv("API_TOKEN") # This will read the API token set in your managed environment
25
  payload = {"inputs": f"{prompt} {trigger_word}"}
26
-
27
- print("Calling query function...")
28
  image_bytes = query(payload, api_url, token)
29
- print("Query function executed successfully.")
30
  return Image.open(image_bytes)
31
 
32
  # Gradio UI
33
  print("Before Gradio Interface")
34
 
35
- # Create a Gradio Blocks interface
36
  with gr.Blocks() as app:
37
  title = gr.HTML("<h1>LoRA the Explorer</h1>")
38
  gallery = gr.Gallery(
@@ -45,25 +40,23 @@ with gr.Blocks() as app:
45
  advanced_options = gr.Accordion("Advanced options", open=False)
46
  weight = gr.Slider(0, 10, value=1, step=0.1, label="LoRA weight")
47
  result = gr.Image(interactive=False, label="Generated Image")
48
-
49
- # Link the function to run when the button is clicked
50
- gr.Row([
51
- gr.Column([
52
- title,
53
- gallery,
54
- prompt,
55
- advanced_options,
56
- weight,
57
- gr.Button("Run", label="Run").click(
58
  fn=run_lora,
59
  inputs=[prompt, weight],
60
  outputs=[result]
61
  )
62
- ]),
63
- gr.Column([result])
64
- ])
65
 
66
  print("After Gradio Interface")
67
 
68
  # Launch the Gradio interface with a queue
69
- app.launch(debug=True, queue=True)
 
17
 
18
  # Define the function to run when the button is clicked
19
  def run_lora(prompt, weight):
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)
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(
 
40
  advanced_options = gr.Accordion("Advanced options", open=False)
41
  weight = gr.Slider(0, 10, value=1, step=0.1, label="LoRA weight")
42
  result = gr.Image(interactive=False, label="Generated Image")
43
+
44
+ with gr.Row():
45
+ with gr.Column():
46
+ title
47
+ gallery
48
+ prompt
49
+ advanced_options
50
+ weight
51
+ gr.Button("Run").click(
 
52
  fn=run_lora,
53
  inputs=[prompt, weight],
54
  outputs=[result]
55
  )
56
+ with gr.Column():
57
+ result
 
58
 
59
  print("After Gradio Interface")
60
 
61
  # Launch the Gradio interface with a queue
62
+ app.launch(share=True, debug=True, queue=True)