Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,12 @@
|
|
1 |
-
import
|
2 |
-
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
-
from PIL import Image
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
return
|
13 |
|
14 |
-
|
15 |
-
fn=generate_caption,
|
16 |
-
inputs=gr.Image(type="pil"),
|
17 |
-
outputs="text",
|
18 |
-
title="Image-to-Text Captioning",
|
19 |
-
description="Upload an image to generate a caption!"
|
20 |
-
)
|
21 |
-
|
22 |
-
interface.launch()
|
|
|
1 |
+
import requests
|
|
|
|
|
2 |
|
3 |
+
API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-base"
|
4 |
+
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
5 |
|
6 |
+
def query(filename):
|
7 |
+
with open(filename, "rb") as f:
|
8 |
+
data = f.read()
|
9 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
10 |
+
return response.json()
|
11 |
|
12 |
+
output = query("cats.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|