florafeng commited on
Commit
7f23a9a
·
verified ·
1 Parent(s): 0d4166b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -4,18 +4,29 @@ import base64
4
  from PIL import Image
5
  from io import BytesIO
6
 
7
- API_URL = "https://huggingface.co/spaces/florafeng/UCLIP-IMG-GEN/"
8
 
9
 
10
  def generate(prompt, seed):
11
  response = requests.post(
12
  API_URL,
13
- json={"prompt": prompt, "seed": int(seed)}
 
 
14
  )
15
 
16
- data = response.json()
 
17
 
18
- img_bytes = base64.b64decode(data["image"])
 
 
 
 
 
 
 
 
19
  image = Image.open(BytesIO(img_bytes))
20
 
21
  return image
 
4
  from PIL import Image
5
  from io import BytesIO
6
 
7
+ API_URL = "https://florafeng-uclip-img-gen.hf.space/run/predict"
8
 
9
 
10
  def generate(prompt, seed):
11
  response = requests.post(
12
  API_URL,
13
+ json={
14
+ "data": [prompt, int(seed)]
15
+ }
16
  )
17
 
18
+ if response.status_code != 200:
19
+ return f"Error: {response.status_code} - {response.text}"
20
 
21
+ try:
22
+ data = response.json()
23
+ except Exception:
24
+ return f"Invalid JSON response: {response.text}"
25
+
26
+ # Gradio responses are usually in: data["data"]
27
+ img_base64 = data["data"][0]
28
+
29
+ img_bytes = base64.b64decode(img_base64)
30
  image = Image.open(BytesIO(img_bytes))
31
 
32
  return image