Update README.md
Browse files
README.md
CHANGED
|
@@ -202,3 +202,29 @@ def run_inference(model, processor, messages, max_new_tokens=128, device="cuda")
|
|
| 202 |
)
|
| 203 |
return outputs[0]
|
| 204 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
)
|
| 203 |
return outputs[0]
|
| 204 |
```
|
| 205 |
+
|
| 206 |
+
### End-to-End Example
|
| 207 |
+
|
| 208 |
+
```python
|
| 209 |
+
model = load_model("taresco/KarantaOCR")
|
| 210 |
+
processor = load_processor("taresco/KarantaOCR")
|
| 211 |
+
|
| 212 |
+
prompt = """Below is the image of one page of a PDF document.
|
| 213 |
+
Just return the plain text representation of this document as if you were reading it naturally.
|
| 214 |
+
Turn equations into a LaTeX representation, and tables into markdown format. Remove the headers and footers, but keep references and footnotes.
|
| 215 |
+
Read any natural handwriting.
|
| 216 |
+
This is likely one page out of several in the document, so be sure to preserve any sentences that come from the previous page, or continue onto the next page, exactly as they are.
|
| 217 |
+
If there is no text at all that you think you should read, you can output null.
|
| 218 |
+
if the document contains diacritics, please include them in the output.
|
| 219 |
+
Do not hallucinate.
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
messages = build_message(
|
| 223 |
+
image_url="example.pdf",
|
| 224 |
+
system_prompt=prompt,
|
| 225 |
+
page=0
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
output_text = run_inference(model, processor, messages)
|
| 229 |
+
print(output_text)
|
| 230 |
+
```
|