Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from transformers import MllamaForConditionalGeneration, AutoProcessor
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
|
@@ -6,18 +6,10 @@ import spaces
|
|
| 6 |
|
| 7 |
# Initialize model and processor
|
| 8 |
ckpt = "unsloth/Llama-3.2-11B-Vision-Instruct"
|
| 9 |
-
bnb_config = BitsAndBytesConfig(
|
| 10 |
-
load_in_4bit=True, # Quantification 4-bit pour économiser la VRAM
|
| 11 |
-
bnb_4bit_use_double_quant=True,
|
| 12 |
-
bnb_4bit_quant_type="nf4",
|
| 13 |
-
bnb_4bit_compute_dtype=torch.float16
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
model = MllamaForConditionalGeneration.from_pretrained(
|
| 17 |
ckpt,
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
)
|
| 21 |
processor = AutoProcessor.from_pretrained(ckpt)
|
| 22 |
|
| 23 |
@spaces.GPU
|
|
@@ -37,9 +29,6 @@ def extract_text(image):
|
|
| 37 |
"- Do NOT separate handwritten and printed text.\n"
|
| 38 |
"- Do NOT confuse '.' (a period) with '|' (a border).\n\n"
|
| 39 |
"Only extract the text that is actually visible in the image, and nothing else.")
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
# Create message structure
|
| 44 |
messages = [
|
| 45 |
{
|
|
@@ -67,9 +56,9 @@ def extract_text(image):
|
|
| 67 |
result = result[result.lower().find("assistant") + len("assistant"):].strip()
|
| 68 |
|
| 69 |
# Remove any remaining conversation markers
|
| 70 |
-
|
| 71 |
|
| 72 |
-
print(
|
| 73 |
|
| 74 |
return result
|
| 75 |
|
|
|
|
| 1 |
+
from transformers import MllamaForConditionalGeneration, AutoProcessor
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
|
|
|
| 6 |
|
| 7 |
# Initialize model and processor
|
| 8 |
ckpt = "unsloth/Llama-3.2-11B-Vision-Instruct"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
model = MllamaForConditionalGeneration.from_pretrained(
|
| 10 |
ckpt,
|
| 11 |
+
torch_dtype=torch.bfloat16
|
| 12 |
+
).to("cuda")
|
|
|
|
| 13 |
processor = AutoProcessor.from_pretrained(ckpt)
|
| 14 |
|
| 15 |
@spaces.GPU
|
|
|
|
| 29 |
"- Do NOT separate handwritten and printed text.\n"
|
| 30 |
"- Do NOT confuse '.' (a period) with '|' (a border).\n\n"
|
| 31 |
"Only extract the text that is actually visible in the image, and nothing else.")
|
|
|
|
|
|
|
|
|
|
| 32 |
# Create message structure
|
| 33 |
messages = [
|
| 34 |
{
|
|
|
|
| 56 |
result = result[result.lower().find("assistant") + len("assistant"):].strip()
|
| 57 |
|
| 58 |
# Remove any remaining conversation markers
|
| 59 |
+
result = result.replace("user", "").replace(prompt, "").strip()
|
| 60 |
|
| 61 |
+
print(result)
|
| 62 |
|
| 63 |
return result
|
| 64 |
|