commit 902abbf84c3a93ac1d35ec327305e1e0c3d59a16 Author: SOULOFCINDER <841135647@qq.com> Date: Fri Apr 7 09:29:46 2023 +0800 the app.py is needed to fix bug diff --git a/layoutlmv3_base_mpdocvqa/Dockerfile b/layoutlmv3_base_mpdocvqa/Dockerfile new file mode 100644 index 0000000..d525920 --- /dev/null +++ b/layoutlmv3_base_mpdocvqa/Dockerfile @@ -0,0 +1,25 @@ +# please visit https://github.com/xfyun/aiges/releases to get stable and suitable iamges. + +FROM docker.io/library/python:3.8.9 + + +RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list +RUN sed -i 's|security.debian.org/debian-security|mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list + + +WORKDIR /home/user/app +RUN useradd -m -u 1000 user +RUN chown -R 1000.1000 /home/user + + +RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/ + + +RUN pip install --no-cache-dir pip==22.3.1 +RUN --mount=target=requirements.txt,source=requirements.txt pip install --no-cache-dir -r requirements.txt + + +COPY --chown=1000 ./ /home/user/app + + +CMD ["python3", "app.py"] \ No newline at end of file diff --git a/layoutlmv3_base_mpdocvqa/Masahiro.png b/layoutlmv3_base_mpdocvqa/Masahiro.png new file mode 100644 index 0000000..1a43102 Binary files /dev/null and b/layoutlmv3_base_mpdocvqa/Masahiro.png differ diff --git a/layoutlmv3_base_mpdocvqa/app.py b/layoutlmv3_base_mpdocvqa/app.py new file mode 100644 index 0000000..854f588 --- /dev/null +++ b/layoutlmv3_base_mpdocvqa/app.py @@ -0,0 +1,42 @@ +import gradio as gr +import torch +from transformers import LayoutLMv3Processor, LayoutLMv3ForQuestionAnswering + + +##这个模型的示例存在问题,无法运行 + +def inference(img): + pretrained_model_path = "layoutlmv3-base-mpdocvqa" + processor = LayoutLMv3Processor.from_pretrained(pretrained_model_path, apply_ocr=False) + model = LayoutLMv3ForQuestionAnswering.from_pretrained(pretrained_model_path) + + image = img.convert("RGB") + question = "Is this a question?" + context = ["Example"] + boxes = [0, 0, 1000, 1000] # This is an example bounding box covering the whole image. + document_encoding = processor(image, question, context, boxes=boxes, return_tensors="pt") + outputs = model(**document_encoding) + + # Get the answer + start_idx = torch.argmax(outputs.start_logits, axis=1) + end_idx = torch.argmax(outputs.end_logits, axis=1) + answers = processor.tokenizer.decode(input_tokens[start_idx: end_idx + 1]).strip() + return answers + + + +title = "layoutlmv3-base-mpdocvqa" +description = "Gradio Demo for layoutlmv3-base-mpdocvqa. To use it, simply upload your image, or click one of the examples to load them." +article = "