akhaliq HF Staff commited on
Commit
17cc4e0
·
verified ·
1 Parent(s): e1f8042

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -24,6 +24,22 @@ def get_headers():
24
  "X-HF-Bill-To": "huggingface"
25
  }
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def upload_image_to_fal(image_bytes):
28
  """Upload image to fal.ai and return the URL"""
29
  # For now, we'll use base64 data URI as mentioned in the docs
 
24
  "X-HF-Bill-To": "huggingface"
25
  }
26
 
27
+ def query_api(payload):
28
+ """Send request to the API and return response"""
29
+ headers = get_headers()
30
+
31
+ # Convert image to base64 if it's bytes
32
+ if "image_bytes" in payload:
33
+ payload["inputs"] = base64.b64encode(payload["image_bytes"]).decode("utf-8")
34
+ del payload["image_bytes"]
35
+
36
+ response = requests.post(API_URL, headers=headers, json=payload)
37
+
38
+ if response.status_code != 200:
39
+ raise gr.Error(f"API request failed with status {response.status_code}: {response.text}")
40
+
41
+ return response.content
42
+
43
  def upload_image_to_fal(image_bytes):
44
  """Upload image to fal.ai and return the URL"""
45
  # For now, we'll use base64 data URI as mentioned in the docs