Spaces:
Runtime error
Runtime error
Commit
Β·
8f128da
1
Parent(s):
15a56bc
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,23 +10,24 @@ model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b
|
|
| 10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
model.to(device)
|
| 12 |
|
| 13 |
-
def predict(inp):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
demo = gr.Interface(fn=predict,
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
def predict(imageurl):
|
|
|
|
| 26 |
inputs = processor(image, return_tensors="pt")
|
| 27 |
generated_ids = model.generate(**inputs, max_new_tokens=20)
|
| 28 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
| 29 |
-
|
| 30 |
|
| 31 |
demo = gr.Interface(fn=predict,
|
| 32 |
inputs="text",
|
|
|
|
| 10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
model.to(device)
|
| 12 |
|
| 13 |
+
# def predict(inp):
|
| 14 |
+
# inp = transforms.ToTensor()(inp).unsqueeze(0)
|
| 15 |
+
# with torch.no_grad():
|
| 16 |
+
# prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
| 17 |
+
# confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
| 18 |
+
# return confidences
|
| 19 |
|
| 20 |
+
# demo = gr.Interface(fn=predict,
|
| 21 |
+
# inputs=gr.inputs.Image(type="pil"),
|
| 22 |
+
# outputs=gr.outputs.Label(num_top_classes=3)
|
| 23 |
+
# )
|
| 24 |
|
| 25 |
def predict(imageurl):
|
| 26 |
+
image = Image.open(requests.get(imageurl, stream=True).raw).convert('RGB')
|
| 27 |
inputs = processor(image, return_tensors="pt")
|
| 28 |
generated_ids = model.generate(**inputs, max_new_tokens=20)
|
| 29 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
| 30 |
+
return('caption: '+generated_text)
|
| 31 |
|
| 32 |
demo = gr.Interface(fn=predict,
|
| 33 |
inputs="text",
|