Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -26,13 +26,13 @@ recognitor = Predictor(config)
|
|
26 |
#model_name = "microsoft/xdoc-base-squad2.0"
|
27 |
#nlp = pipeline('question-answering', model=model_name)
|
28 |
|
29 |
-
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
30 |
-
|
31 |
-
model_name = "timpal0l/mdeberta-v3-base-squad2"
|
32 |
-
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
33 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
34 |
-
nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
def query(doc, labels):
|
37 |
questions = labels.split(", ")
|
38 |
result={}
|
@@ -47,7 +47,7 @@ def query(doc, labels):
|
|
47 |
value = res['answer']
|
48 |
result[question]=value
|
49 |
return result
|
50 |
-
|
51 |
def draw_boxes(image, bounds, color='yellow', width=2):
|
52 |
draw = ImageDraw.Draw(image)
|
53 |
for bound in bounds:
|
@@ -88,8 +88,9 @@ def inference(filepath, lang, labels):
|
|
88 |
out = recognitor.predict(cropped_image)
|
89 |
|
90 |
texts = texts + '\t' + out
|
91 |
-
result = query(texts, labels)
|
92 |
-
jsonText = json.dumps(result)
|
|
|
93 |
im = PIL.Image.open(filepath)
|
94 |
draw_boxes(im, bounds)
|
95 |
im.save('result.jpg')
|
|
|
26 |
#model_name = "microsoft/xdoc-base-squad2.0"
|
27 |
#nlp = pipeline('question-answering', model=model_name)
|
28 |
|
29 |
+
#from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
#model_name = "timpal0l/mdeberta-v3-base-squad2"
|
32 |
+
#model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
33 |
+
#tokenizer = AutoTokenizer.from_pretrained(model_name)
|
34 |
+
#nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
|
35 |
+
'''
|
36 |
def query(doc, labels):
|
37 |
questions = labels.split(", ")
|
38 |
result={}
|
|
|
47 |
value = res['answer']
|
48 |
result[question]=value
|
49 |
return result
|
50 |
+
'''
|
51 |
def draw_boxes(image, bounds, color='yellow', width=2):
|
52 |
draw = ImageDraw.Draw(image)
|
53 |
for bound in bounds:
|
|
|
88 |
out = recognitor.predict(cropped_image)
|
89 |
|
90 |
texts = texts + '\t' + out
|
91 |
+
#result = query(texts, labels)
|
92 |
+
#jsonText = json.dumps(result)
|
93 |
+
jsonText='{"result":"ok"'
|
94 |
im = PIL.Image.open(filepath)
|
95 |
draw_boxes(im, bounds)
|
96 |
im.save('result.jpg')
|