Spaces:
Runtime error
Runtime error
Commit
·
897869f
1
Parent(s):
50526d9
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,12 +9,13 @@ device='cpu'
|
|
| 9 |
processor = AutoProcessor.from_pretrained("microsoft/git-base")
|
| 10 |
model = AutoModelForCausalLM.from_pretrained("nkasmanoff/git-planet").to(device)
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
def predict(image,max_length=64,device='cpu'):
|
| 14 |
pixel_values = processor(images=image, return_tensors="pt").to(device).pixel_values
|
| 15 |
generated_ids = model.generate(pixel_values=pixel_values, max_length=max_length)
|
| 16 |
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 17 |
-
relation =
|
| 18 |
|
| 19 |
entity_pair = get_entities(generated_caption)
|
| 20 |
|
|
@@ -78,7 +79,6 @@ def get_entities(sent):
|
|
| 78 |
|
| 79 |
|
| 80 |
def get_relation(sent):
|
| 81 |
-
nlp = spacy.load('en_core_web_sm')
|
| 82 |
|
| 83 |
doc = nlp(sent)
|
| 84 |
|
|
|
|
| 9 |
processor = AutoProcessor.from_pretrained("microsoft/git-base")
|
| 10 |
model = AutoModelForCausalLM.from_pretrained("nkasmanoff/git-planet").to(device)
|
| 11 |
|
| 12 |
+
nlp = spacy.load('en_core_web_sm')
|
| 13 |
|
| 14 |
def predict(image,max_length=64,device='cpu'):
|
| 15 |
pixel_values = processor(images=image, return_tensors="pt").to(device).pixel_values
|
| 16 |
generated_ids = model.generate(pixel_values=pixel_values, max_length=max_length)
|
| 17 |
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 18 |
+
relation = get_relation(generated_caption)
|
| 19 |
|
| 20 |
entity_pair = get_entities(generated_caption)
|
| 21 |
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
def get_relation(sent):
|
|
|
|
| 82 |
|
| 83 |
doc = nlp(sent)
|
| 84 |
|