qtoino commited on
Commit
345110e
·
verified ·
1 Parent(s): 20f10b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -5,10 +5,10 @@ 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,
@@ -25,7 +25,10 @@ def save_to_dataset(images, questions, answer_p2s_base, answer_p2s_large, answer
25
 
26
  def generate_answer(image_path, question, model_name, space_id):
27
  try:
28
- client = Client(f"https://{model_name}.hf.space/")
 
 
 
29
  result = client.predict(image_path, question, api_name="/predict")
30
  if result.endswith(".json"):
31
  with open(result, "rb") as json_file:
@@ -51,7 +54,7 @@ def generate_answers(image_path, question):
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
 
 
5
 
6
  import datasets
7
 
8
+ def save_to_dataset(image_path, questions, answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut):
9
  # Create a dataset dictionary
10
  dataset_dict = {
11
+ "image": image_path,
12
  "question": questions,
13
  "answer_p2s_base": answer_p2s_base,
14
  "answer_p2s_large": answer_p2s_large,
 
25
 
26
  def generate_answer(image_path, question, model_name, space_id):
27
  try:
28
+ if model_name == "qtoino-pix2struct":
29
+ client = Client(f"https://{model_name}.hf.space/--replicas/uax51/")
30
+ else:
31
+ client = Client(f"https://{model_name}.hf.space/")
32
  result = client.predict(image_path, question, api_name="/predict")
33
  if result.endswith(".json"):
34
  with open(result, "rb") as json_file:
 
54
  answer_donut = generate_answer(image_path, question, model_name = "nielsr-donut-docvqa", space_id = "Donut DocVQA")
55
 
56
  # Save the data to the dataset
57
+ save_to_dataset(image_path, questions, answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut)
58
 
59
  return answer_p2s_base, answer_p2s_large, answer_layoutlm, answer_donut
60