Divyam Sharma commited on
Commit
169c40b
1 Parent(s): 844f195

Img Gen Rev3

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -28,6 +28,22 @@ def get_completion(inputs, parameters=None, ENDPOINT_URL=""):
28
  data=json.dumps(data))
29
  return json.loads(response.content.decode("utf-8"))
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  #text-to-image
32
  TTI_ENDPOINT = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"
33
  # "http://jupyter-api-proxy.internal.dlai/rev-proxy/huggingface/itt"
@@ -58,8 +74,8 @@ def captioner(image):
58
  return result[0]['generated_text']
59
 
60
  def generate(prompt):
61
- output = get_completion(prompt, None, TTI_ENDPOINT)
62
- image = Image.open(io.BytesIO(output.content))
63
  return image
64
  # result_image = base64_to_pil(output.content)
65
  # return result_image
 
28
  data=json.dumps(data))
29
  return json.loads(response.content.decode("utf-8"))
30
 
31
+ def get_img_completion(inputs, parameters=None, ENDPOINT_URL=""):
32
+ headers = {
33
+ "Authorization": f"Bearer {hf_api_key}",
34
+ "Content-Type": "application/json"
35
+ }
36
+ data = { "inputs": inputs }
37
+ if parameters is not None:
38
+ data.update({"parameters": parameters})
39
+ response = requests.request("POST",
40
+ ENDPOINT_URL,
41
+ headers=headers,
42
+ data=json.dumps(data))
43
+ return response.content
44
+ # return json.loads(response.content.decode("utf-8"))
45
+
46
+
47
  #text-to-image
48
  TTI_ENDPOINT = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"
49
  # "http://jupyter-api-proxy.internal.dlai/rev-proxy/huggingface/itt"
 
74
  return result[0]['generated_text']
75
 
76
  def generate(prompt):
77
+ output = get_img_completion(prompt, None, TTI_ENDPOINT)
78
+ image = Image.open(io.BytesIO(output))
79
  return image
80
  # result_image = base64_to_pil(output.content)
81
  # return result_image