Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoProcessor, AutoModelForCausalLM, BlipForQuestionAnswering, ViltForQuestionAnswering
|
3 |
import torch
|
|
|
4 |
|
5 |
torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
|
6 |
torch.hub.download_url_to_file('https://huggingface.co/datasets/nielsr/textcaps-sample/resolve/main/stop_sign.png', 'stop_sign.png')
|
@@ -68,7 +69,7 @@ def generate_answer_vilt(processor, model, image, question):
|
|
68 |
predicted_class_idx = outputs.logits.argmax(-1).item()
|
69 |
logitsList = outputs.logits.tolist()
|
70 |
print(logitsList)
|
71 |
-
maybeProbsList = [exp(i) for i in logitsList]
|
72 |
return model.config.id2label[predicted_class_idx]
|
73 |
|
74 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoProcessor, AutoModelForCausalLM, BlipForQuestionAnswering, ViltForQuestionAnswering
|
3 |
import torch
|
4 |
+
import math
|
5 |
|
6 |
torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
|
7 |
torch.hub.download_url_to_file('https://huggingface.co/datasets/nielsr/textcaps-sample/resolve/main/stop_sign.png', 'stop_sign.png')
|
|
|
69 |
predicted_class_idx = outputs.logits.argmax(-1).item()
|
70 |
logitsList = outputs.logits.tolist()
|
71 |
print(logitsList)
|
72 |
+
maybeProbsList = [math.exp(i) for i in logitsList]
|
73 |
return model.config.id2label[predicted_class_idx]
|
74 |
|
75 |
|