Spaces:
Runtime error
Runtime error
Commit
·
b39f788
1
Parent(s):
8ab30b2
Update app.py
Browse files
app.py
CHANGED
@@ -6,35 +6,35 @@ import IPython.display
|
|
6 |
from PIL import Image
|
7 |
import base64
|
8 |
|
9 |
-
def greet(name):
|
10 |
-
return "Hello " + name +os.environ['HF_TOKENS']
|
11 |
|
12 |
|
13 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
14 |
|
15 |
-
demo.launch()
|
16 |
|
17 |
|
18 |
#gr.close_all()
|
19 |
#gr.Textbox(os.environ['HF_TOKENS'])
|
20 |
|
21 |
#Image-to-text endpoint
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
|
39 |
def image_to_base64_str(pil_image):
|
40 |
byte_arr = io.BytesIO()
|
@@ -65,4 +65,4 @@ def captioner(image):
|
|
65 |
# // allow_flagging="never",
|
66 |
# // examples=["christmas_dog.jpeg", "bird_flight.jpeg", "cow.jpeg"])
|
67 |
|
68 |
-
|
|
|
6 |
from PIL import Image
|
7 |
import base64
|
8 |
|
9 |
+
#def greet(name):
|
10 |
+
# return "Hello " + name +os.environ['HF_TOKENS']
|
11 |
|
12 |
|
13 |
+
#demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
14 |
|
15 |
+
#demo.launch()
|
16 |
|
17 |
|
18 |
#gr.close_all()
|
19 |
#gr.Textbox(os.environ['HF_TOKENS'])
|
20 |
|
21 |
#Image-to-text endpoint
|
22 |
+
def get_completion(inputs, parameters=None, ENDPOINT_URL="http://internal-aws-prod-internal-revproxy-alb-11660607.us-west-1.elb.amazonaws.com/rev-proxy/huggingface/itt"):
|
23 |
+
headers = {
|
24 |
+
"Authorization": f"Bearer {os.environ['HF_TOKENS']}",
|
25 |
+
"Content-Type": "application/json"
|
26 |
+
}
|
27 |
+
data = { "inputs": inputs }
|
28 |
+
if parameters is not None:
|
29 |
+
data.update({"parameters": parameters})
|
30 |
+
response = requests.request("POST",
|
31 |
+
ENDPOINT_URL,
|
32 |
+
headers=headers,
|
33 |
+
data=json.dumps(data))
|
34 |
+
return json.loads(response.content.decode("utf-8"))
|
35 |
|
36 |
+
image_url = "https://free-images.com/sm/9596/dog_animal_greyhound_983023.jpg"
|
37 |
+
demo = gr.Textbox(get_completion(image_url))
|
38 |
|
39 |
def image_to_base64_str(pil_image):
|
40 |
byte_arr = io.BytesIO()
|
|
|
65 |
# // allow_flagging="never",
|
66 |
# // examples=["christmas_dog.jpeg", "bird_flight.jpeg", "cow.jpeg"])
|
67 |
|
68 |
+
demo.launch()
|