Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,25 @@ from gradio_client import Client
|
|
3 |
import os
|
4 |
import json
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def generate_answer(image_path, question, model_name, space_id):
|
8 |
try:
|
@@ -31,6 +50,9 @@ def generate_answers(image_path, question):
|
|
31 |
|
32 |
answer_donut = generate_answer(image_path, question, model_name = "nielsr-donut-docvqa", space_id = "Donut DocVQA")
|
33 |
|
|
|
|
|
|
|
34 |
return answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut
|
35 |
|
36 |
examples = [["docvqa_example.png", "How many items are sold?"], ["document-question-answering-input.png", "What is the objective?"]]
|
|
|
3 |
import os
|
4 |
import json
|
5 |
|
6 |
+
import datasets
|
7 |
+
|
8 |
+
def save_to_dataset(images, questions, answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut):
|
9 |
+
# Create a dataset dictionary
|
10 |
+
dataset_dict = {
|
11 |
+
"image": images,
|
12 |
+
"question": questions,
|
13 |
+
"answer_p2s_base": answer_p2s_base,
|
14 |
+
"answer_p2s_large": answer_p2s_large,
|
15 |
+
"answer_layoutlm": answer_layoutlm,
|
16 |
+
"answer_donut": answer_donut
|
17 |
+
}
|
18 |
+
|
19 |
+
# Convert the dictionary to a Dataset object
|
20 |
+
dataset = datasets.Dataset.from_dict(dataset_dict)
|
21 |
+
|
22 |
+
# Save the dataset to Hugging Face
|
23 |
+
dataset.save_to_disk("img_question_dataset")
|
24 |
+
|
25 |
|
26 |
def generate_answer(image_path, question, model_name, space_id):
|
27 |
try:
|
|
|
50 |
|
51 |
answer_donut = generate_answer(image_path, question, model_name = "nielsr-donut-docvqa", space_id = "Donut DocVQA")
|
52 |
|
53 |
+
# Save the data to the dataset
|
54 |
+
save_to_dataset(images, questions, answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut)
|
55 |
+
|
56 |
return answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut
|
57 |
|
58 |
examples = [["docvqa_example.png", "How many items are sold?"], ["document-question-answering-input.png", "What is the objective?"]]
|