Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
4 |
# Загружаем модель
|
5 |
-
model =
|
6 |
|
7 |
-
#
|
8 |
-
def generate_answer(image, prompt):
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
# Если
|
13 |
-
if prompt:
|
14 |
-
|
15 |
|
16 |
-
#
|
17 |
-
answer = model
|
18 |
|
|
|
19 |
return answer
|
20 |
|
21 |
-
# Создаем интерфейс
|
22 |
-
gr.Interface(generate_answer, inputs=[gr.Image(), gr.Text()], outputs=gr.Text()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForVisualQuestionAnswering
|
4 |
|
5 |
# Загружаем модель
|
6 |
+
model = AutoModelForVisualQuestionAnswering.from_pretrained("microsoft/visual-turing-nlg-question-answering")
|
7 |
|
8 |
+
# Создаем интерфейс gradio
|
9 |
+
def generate_answer(image, prompt=None):
|
10 |
+
# Преобразуем изображение в тензор
|
11 |
+
image = torch.as_tensor(image)
|
12 |
|
13 |
+
# Если указан дополнительный prompt, добавляем его к запросу
|
14 |
+
if prompt is not None:
|
15 |
+
prompt = f"{prompt} {image.shape[1]} {image.shape[0]}"
|
16 |
|
17 |
+
# Получаем ответ от модели
|
18 |
+
answer = model(image, prompt=prompt).logits[0].argmax(dim=-1)
|
19 |
|
20 |
+
# Возвращаем ответ
|
21 |
return answer
|
22 |
|
23 |
+
# Создаем интерфейс
|
24 |
+
gr.Interface(generate_answer, inputs=[gr.Image(), gr.Text()], outputs=gr.Text())
|