Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ from PIL import Image
|
|
4 |
import requests
|
5 |
import gradio as gr
|
6 |
import spaces
|
|
|
|
|
7 |
|
8 |
model_id = "yifeihu/TB-OCR-preview-0.1"
|
9 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
@@ -20,7 +22,7 @@ processor = AutoProcessor.from_pretrained(model_id,
|
|
20 |
num_crops=16
|
21 |
)
|
22 |
|
23 |
-
|
24 |
def phi_ocr(image):
|
25 |
question = "Convert the text to markdown format."
|
26 |
prompt_message = [{
|
@@ -40,6 +42,7 @@ def phi_ocr(image):
|
|
40 |
response = response.split("<image_end>")[0]
|
41 |
return response
|
42 |
|
|
|
43 |
def process_image(input_image):
|
44 |
return phi_ocr(input_image)
|
45 |
|
|
|
4 |
import requests
|
5 |
import gradio as gr
|
6 |
import spaces
|
7 |
+
import subprocess
|
8 |
+
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
9 |
|
10 |
model_id = "yifeihu/TB-OCR-preview-0.1"
|
11 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
22 |
num_crops=16
|
23 |
)
|
24 |
|
25 |
+
|
26 |
def phi_ocr(image):
|
27 |
question = "Convert the text to markdown format."
|
28 |
prompt_message = [{
|
|
|
42 |
response = response.split("<image_end>")[0]
|
43 |
return response
|
44 |
|
45 |
+
@spaces.GPU
|
46 |
def process_image(input_image):
|
47 |
return phi_ocr(input_image)
|
48 |
|