pratikshahp commited on
Commit
16cb436
·
verified ·
1 Parent(s): 3e4f277

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
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
- 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]
@@ -46,10 +47,11 @@ def generate_compliment(image):
46
  "top_k": 50,
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]
@@ -70,4 +72,4 @@ iface = gr.Interface(
70
  description="Upload your headshot and get a personalized compliment!"
71
  )
72
 
73
- iface.launch(share=True)
 
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()