Spaces:
Runtime error
Runtime error
Commit
·
90cb8f1
1
Parent(s):
5ccfd0c
Update app.py
Browse files
app.py
CHANGED
@@ -27,17 +27,45 @@ def update_selection(selected_state: gr.SelectData):
|
|
27 |
)
|
28 |
|
29 |
def run_lora(prompt, selected_state, progress=gr.Progress(track_tqdm=True)):
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
selected_lora = loras[selected_lora_index]
|
32 |
api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
def apply_post_processing(image, downscale, limit_colors, grayscale, black_and_white):
|
43 |
processed_image = image.copy()
|
|
|
27 |
)
|
28 |
|
29 |
def run_lora(prompt, selected_state, progress=gr.Progress(track_tqdm=True)):
|
30 |
+
logging.debug(f"Inside run_lora, selected_state: {selected_state}")
|
31 |
+
if not selected_state:
|
32 |
+
logging.error("selected_state is None or empty.")
|
33 |
+
raise gr.Error("You must select a LoRA before proceeding.") # Popup error when no LoRA is selected
|
34 |
+
|
35 |
+
selected_lora_index = selected_state.index # Changed this line
|
36 |
selected_lora = loras[selected_lora_index]
|
37 |
api_url = f"https://api-inference.huggingface.co/models/{selected_lora['repo']}"
|
38 |
+
trigger_word = selected_lora["trigger_word"]
|
39 |
+
#token = os.getenv("API_TOKEN")
|
40 |
+
payload = {
|
41 |
+
"inputs": f"{prompt} {trigger_word}",
|
42 |
+
"parameters":{"negative_prompt": "bad art, ugly, watermark, deformed"},
|
43 |
+
}
|
44 |
+
#headers = {"Authorization": f"Bearer {token}"}
|
45 |
+
|
46 |
+
# Add a print statement to display the API request
|
47 |
+
print(f"API Request: {api_url}")
|
48 |
+
#print(f"API Headers: {headers}")
|
49 |
+
print(f"API Payload: {payload}")
|
50 |
+
|
51 |
+
error_count = 0
|
52 |
+
pbar = tqdm(total=None, desc="Loading model")
|
53 |
+
while(True):
|
54 |
+
response = requests.post(api_url, json=payload)
|
55 |
+
if response.status_code == 200:
|
56 |
+
return Image.open(io.BytesIO(response.content))
|
57 |
+
elif response.status_code == 503:
|
58 |
+
#503 is triggered when the model is doing cold boot. It also gives you a time estimate from when the model is loaded but it is not super precise
|
59 |
+
time.sleep(1)
|
60 |
+
pbar.update(1)
|
61 |
+
elif response.status_code == 500 and error_count < 5:
|
62 |
+
print(response.content)
|
63 |
+
time.sleep(1)
|
64 |
+
error_count += 1
|
65 |
+
continue
|
66 |
+
else:
|
67 |
+
logging.error(f"API Error: {response.status_code}")
|
68 |
+
raise gr.Error("API Error: Unable to fetch the image.") # Raise a Gradio error here
|
69 |
|
70 |
def apply_post_processing(image, downscale, limit_colors, grayscale, black_and_white):
|
71 |
processed_image = image.copy()
|