Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,12 +24,19 @@ def generate_compliment(image):
|
|
24 |
image_bytes = buffered.getvalue()
|
25 |
|
26 |
# Connect to the captioning model on Hugging Face Spaces
|
27 |
-
captioning_url = "https://
|
28 |
-
caption_response = requests.post(captioning_url, files={"image": image_bytes})
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
# Connect to the LLM model on Hugging Face Spaces
|
32 |
-
llm_url = "https://
|
33 |
llm_payload = {
|
34 |
"system_prompt": SYSTEM_PROMPT,
|
35 |
"message": f"Caption: {caption}\nCompliment: ",
|
@@ -40,7 +47,14 @@ def generate_compliment(image):
|
|
40 |
"repetition_penalty": 1,
|
41 |
}
|
42 |
llm_response = requests.post(llm_url, json=llm_payload)
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
return caption, compliment
|
46 |
|
@@ -53,7 +67,8 @@ iface = gr.Interface(
|
|
53 |
gr.Textbox(label="Compliment")
|
54 |
],
|
55 |
title="Compliment Bot π",
|
56 |
-
description="Upload your headshot and get a personalized compliment!"
|
|
|
57 |
)
|
58 |
|
59 |
iface.launch()
|
|
|
24 |
image_bytes = buffered.getvalue()
|
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 |
+
caption_response = requests.post(captioning_url, files={"image": ("image.jpg", image_bytes, "image/jpeg")})
|
29 |
+
|
30 |
+
if caption_response.status_code != 200:
|
31 |
+
return "Error", f"Failed to get caption. Status code: {caption_response.status_code}, Response: {caption_response.text}"
|
32 |
+
|
33 |
+
try:
|
34 |
+
caption = caption_response.json()["data"][0]
|
35 |
+
except Exception as e:
|
36 |
+
return "Error", f"Failed to parse caption response. Error: {str(e)}, Response: {caption_response.text}"
|
37 |
|
38 |
# Connect to the LLM model on Hugging Face Spaces
|
39 |
+
llm_url = "https://hysts-zephyr-7b.hf.space/run/chat"
|
40 |
llm_payload = {
|
41 |
"system_prompt": SYSTEM_PROMPT,
|
42 |
"message": f"Caption: {caption}\nCompliment: ",
|
|
|
47 |
"repetition_penalty": 1,
|
48 |
}
|
49 |
llm_response = requests.post(llm_url, json=llm_payload)
|
50 |
+
|
51 |
+
if llm_response.status_code != 200:
|
52 |
+
return "Error", f"Failed to get compliment. Status code: {llm_response.status_code}, Response: {llm_response.text}"
|
53 |
+
|
54 |
+
try:
|
55 |
+
compliment = llm_response.json()["data"][0]
|
56 |
+
except Exception as e:
|
57 |
+
return "Error", f"Failed to parse LLM response. Error: {str(e)}, Response: {llm_response.text}"
|
58 |
|
59 |
return caption, compliment
|
60 |
|
|
|
67 |
gr.Textbox(label="Compliment")
|
68 |
],
|
69 |
title="Compliment Bot π",
|
70 |
+
description="Upload your headshot and get a personalized compliment!",
|
71 |
+
share=True
|
72 |
)
|
73 |
|
74 |
iface.launch()
|