Spaces:
Runtime error
Runtime error
Commit
·
ab14713
1
Parent(s):
f180d69
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,8 +15,24 @@ def query(payload, api_url, token):
|
|
| 15 |
response = requests.post(api_url, headers=headers, json=payload)
|
| 16 |
return io.BytesIO(response.content)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Gradio UI
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
title = gr.HTML(
|
| 21 |
"""<h1><img src="https://i.imgur.com/vT48NAO.png" alt="LoRA"> LoRA the Explorer</h1>""",
|
| 22 |
elem_id="title",
|
|
@@ -34,22 +50,10 @@ with gr.Blocks(css="custom.css") as demo: # Added the css argument with "custom
|
|
| 34 |
weight = gr.Slider(0, 10, value=1, step=0.1, label="LoRA weight")
|
| 35 |
result = gr.Image(interactive=False, label="Generated Image", elem_id="result-image")
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
print("Calling query function...")
|
| 46 |
-
image_bytes = query(payload, api_url, token)
|
| 47 |
-
print("Query function executed successfully.")
|
| 48 |
-
return Image.open(image_bytes)
|
| 49 |
-
|
| 50 |
-
print("Starting Gradio UI...")
|
| 51 |
-
gr.Interface(
|
| 52 |
-
fn=run_lora,
|
| 53 |
-
inputs=[prompt, weight],
|
| 54 |
-
outputs=[result],
|
| 55 |
-
).launch()
|
|
|
|
| 15 |
response = requests.post(api_url, headers=headers, json=payload)
|
| 16 |
return io.BytesIO(response.content)
|
| 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 Blocks")
|
| 34 |
+
with gr.Blocks(css="custom.css") as demo:
|
| 35 |
+
print("Inside Gradio Blocks")
|
| 36 |
title = gr.HTML(
|
| 37 |
"""<h1><img src="https://i.imgur.com/vT48NAO.png" alt="LoRA"> LoRA the Explorer</h1>""",
|
| 38 |
elem_id="title",
|
|
|
|
| 50 |
weight = gr.Slider(0, 10, value=1, step=0.1, label="LoRA weight")
|
| 51 |
result = gr.Image(interactive=False, label="Generated Image", elem_id="result-image")
|
| 52 |
|
| 53 |
+
print("Before Gradio Interface")
|
| 54 |
+
gr.Interface(
|
| 55 |
+
fn=run_lora,
|
| 56 |
+
inputs=[prompt, weight],
|
| 57 |
+
outputs=[result],
|
| 58 |
+
).launch()
|
| 59 |
+
print("After Gradio Interface")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|