Spaces:
Runtime error
Runtime error
artificialguybr
commited on
Commit
•
0347515
1
Parent(s):
987176f
Update app.py
Browse files
app.py
CHANGED
@@ -9,44 +9,36 @@ import os
|
|
9 |
with open('loras.json', 'r') as f:
|
10 |
loras = json.load(f)
|
11 |
|
12 |
-
#
|
13 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
headers = {"Authorization": f"Bearer {token}"}
|
15 |
-
print(f"Sending API request with payload: {payload}")
|
16 |
response = requests.post(api_url, headers=headers, json=payload)
|
17 |
if response.status_code == 200:
|
18 |
-
return io.BytesIO(response.content)
|
19 |
else:
|
20 |
-
|
21 |
-
return None
|
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:
|
26 |
-
selected_lora_index = selected_lora_index[0] # Unpack the tuple
|
27 |
-
selected_lora = loras[selected_lora_index]
|
28 |
-
api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
|
29 |
-
trigger_word = selected_lora["trigger_word"]
|
30 |
-
token = os.getenv("API_TOKEN")
|
31 |
-
payload = {"inputs": f"{prompt} {trigger_word}"}
|
32 |
-
|
33 |
-
# API call
|
34 |
-
image_bytes = query(payload, api_url, token)
|
35 |
-
|
36 |
-
if image_bytes:
|
37 |
-
return Image.open(image_bytes)
|
38 |
-
return "API Error or No LoRA selected"
|
39 |
|
40 |
# Placeholder for gallery.select function
|
41 |
def update_selection(selected=None):
|
42 |
if selected is None:
|
43 |
-
return None
|
44 |
-
return selected[0],
|
45 |
|
46 |
# Gradio UI
|
47 |
with gr.Blocks(css="custom.css") as app:
|
48 |
title = gr.HTML("<h1>LoRA the Explorer</h1>")
|
49 |
-
selected_state = gr.State(
|
50 |
with gr.Row():
|
51 |
gallery = gr.Gallery(
|
52 |
[(item["image"], item["title"]) for item in loras],
|
|
|
9 |
with open('loras.json', 'r') as f:
|
10 |
loras = json.load(f)
|
11 |
|
12 |
+
# Define the function to run when the button is clicked
|
13 |
+
def run_lora(prompt, selected_state):
|
14 |
+
if not selected_state:
|
15 |
+
raise gr.Error("You must select a LoRA")
|
16 |
+
|
17 |
+
selected_lora_index = selected_state['index']
|
18 |
+
selected_lora = loras[selected_lora_index]
|
19 |
+
api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
|
20 |
+
trigger_word = selected_lora["trigger_word"]
|
21 |
+
token = os.getenv("API_TOKEN")
|
22 |
+
payload = {"inputs": f"{prompt} {trigger_word}"}
|
23 |
+
|
24 |
+
# API call
|
25 |
headers = {"Authorization": f"Bearer {token}"}
|
|
|
26 |
response = requests.post(api_url, headers=headers, json=payload)
|
27 |
if response.status_code == 200:
|
28 |
+
return Image.open(io.BytesIO(response.content))
|
29 |
else:
|
30 |
+
return "API Error"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Placeholder for gallery.select function
|
33 |
def update_selection(selected=None):
|
34 |
if selected is None:
|
35 |
+
return None
|
36 |
+
return {'index': selected[0]},
|
37 |
|
38 |
# Gradio UI
|
39 |
with gr.Blocks(css="custom.css") as app:
|
40 |
title = gr.HTML("<h1>LoRA the Explorer</h1>")
|
41 |
+
selected_state = gr.State() # Initialize with empty state
|
42 |
with gr.Row():
|
43 |
gallery = gr.Gallery(
|
44 |
[(item["image"], item["title"]) for item in loras],
|