Skip to content

【开源实习】技术公开课内容测试任务 12 #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
dqa_pipeline = pipeline("document-question-answering", model="hf-internal-testing/tiny-random-layoutlmv2",
tokenizer=tokenizer)

image_url = "https://hf.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png"
image_url = "https://pic.rmb.bdstatic.com/bjh/bc1fe8c9991/250405/6fc560e10aef1529da8d13fb25fc1c7f.jpeg"
question = "How many cats are there?"

outputs = dqa_pipeline(image=image_url, question=question, top_k=2)
Expand All @@ -33,7 +33,7 @@ def process_image_and_ocr(image_path):
dqa_pipeline = pipeline("document-question-answering", model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa",
tokenizer=tokenizer)

image_path = "./path/to/your/invoice/image.png"
image_path = "invoice.png"
words, boxes = process_image_and_ocr(image_path)
question = "What is the invoice number?"

Expand Down
Binary file added Season2.step_into_llm/15.pipeline/invoice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Season2.step_into_llm/15.pipeline/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.6.0/MindSpore/unified/aarch64/mindspore-2.6.0-cp39-cp39-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install mindnlp librosa pytesseract
26 changes: 3 additions & 23 deletions Season2.step_into_llm/15.pipeline/text_generation_demo.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
# pylint: disable=missing-module-docstring
from mindnlp.transformers import pipeline

# Text Generation Demo
generator = pipeline(model="openai-community/gpt2")
outputs = generator("I can't believe you did such a ", do_sample=False)
print(outputs)

# [{'generated_text': "I can't believe you did such a icky thing to me. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I"}]

# Chat Demo
chat1 = [
{"role": "system", "content": "This is a system message."},
{"role": "user", "content": "This is a test"},
{"role": "assistant", "content": "This is a reply"},
]
chat2 = [
{"role": "system", "content": "This is a system message."},
{"role": "user", "content": "This is a second test"},
{"role": "assistant", "content": "This is a reply"},
]
outputs = generator(chat1, do_sample=False, max_new_tokens=10)
print(outputs)

outputs = generator([chat1, chat2], do_sample=False, max_new_tokens=10)
print(outputs)
prompt = "I can't believe you did such a "
outputs = generator(prompt, do_sample=False, max_new_tokens=20)
print(outputs[0]['generated_text'])