Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,10 +25,11 @@ def generate_compliment(image):
|
|
25 |
|
26 |
# Connect to the captioning model on Hugging Face Spaces
|
27 |
captioning_url = "https://gokaygokay-sd3-long-captioner.hf.space/run/create_captions_rich"
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
try:
|
34 |
caption = caption_response.json()["data"][0]
|
@@ -46,10 +47,11 @@ def generate_compliment(image):
|
|
46 |
"top_k": 50,
|
47 |
"repetition_penalty": 1,
|
48 |
}
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
53 |
|
54 |
try:
|
55 |
compliment = llm_response.json()["data"][0]
|
@@ -70,4 +72,4 @@ iface = gr.Interface(
|
|
70 |
description="Upload your headshot and get a personalized compliment!"
|
71 |
)
|
72 |
|
73 |
-
iface.launch(
|
|
|
25 |
|
26 |
# Connect to the captioning model on Hugging Face Spaces
|
27 |
captioning_url = "https://gokaygokay-sd3-long-captioner.hf.space/run/create_captions_rich"
|
28 |
+
try:
|
29 |
+
caption_response = requests.get(captioning_url, files={"image": ("image.jpg", image_bytes, "image/jpeg")})
|
30 |
+
caption_response.raise_for_status() # Raise an exception for HTTP errors
|
31 |
+
except requests.exceptions.RequestException as e:
|
32 |
+
return "Error", f"Failed to get caption. Exception: {e}"
|
33 |
|
34 |
try:
|
35 |
caption = caption_response.json()["data"][0]
|
|
|
47 |
"top_k": 50,
|
48 |
"repetition_penalty": 1,
|
49 |
}
|
50 |
+
try:
|
51 |
+
llm_response = requests.post(llm_url, json=llm_payload)
|
52 |
+
llm_response.raise_for_status() # Raise an exception for HTTP errors
|
53 |
+
except requests.exceptions.RequestException as e:
|
54 |
+
return "Error", f"Failed to get compliment. Exception: {e}"
|
55 |
|
56 |
try:
|
57 |
compliment = llm_response.json()["data"][0]
|
|
|
72 |
description="Upload your headshot and get a personalized compliment!"
|
73 |
)
|
74 |
|
75 |
+
iface.launch()
|