Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
import requests
|
4 |
from PIL import Image
|
5 |
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
# load image examples
|
10 |
-
urls = ['https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSoolxi9yWGAT5SLZShv8vVd0bz47UWRzQC19fDTeE8GmGv_Rn-PCF1pP1rrUx8kOjA4gg&usqp=CAU',
|
11 |
-
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNYtTuSBpZPV_nkBYPMFwVVD9asZOPgHww4epu9EqWgDmXW--sE2o8og40ZfDGo87j5w&usqp=CAU']
|
12 |
-
for idx, url in enumerate(urls):
|
13 |
-
image = Image.open(requests.get(url, stream=True).raw)
|
14 |
-
image.save(f"image_{idx}.png")
|
15 |
|
16 |
def process_image(image):
|
17 |
# prepare image
|
18 |
-
pixel_values =
|
19 |
|
20 |
# generate (no beam search)
|
21 |
generated_ids = model.generate(pixel_values)
|
22 |
|
23 |
# decode
|
24 |
-
generated_text =
|
25 |
|
26 |
return generated_text
|
27 |
|
28 |
-
title = "
|
29 |
-
description = "
|
30 |
-
article = "<p style='text-align: center'
|
31 |
examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]]
|
32 |
|
33 |
#css = """.output_image, .input_image {height: 600px !important}"""
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import VisionEncoderDecoderModel, AutoImageProcessor, BertTokenizerFast
|
3 |
import requests
|
4 |
from PIL import Image
|
5 |
|
6 |
+
image_processor = AutoImageProcessor.from_pretrained("microsoft/swin-base-patch4-window7-224")
|
7 |
+
tokenizer = tokenizer =BertTokenizerFast.from_pretrained("onlplab/alephbert-base")
|
8 |
+
model = VisionEncoderDecoderModel.from_pretrained("sivan22/hdd-words-ocr")
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def process_image(image):
|
12 |
# prepare image
|
13 |
+
pixel_values = image_processor(image, return_tensors="pt").pixel_values
|
14 |
|
15 |
# generate (no beam search)
|
16 |
generated_ids = model.generate(pixel_values)
|
17 |
|
18 |
# decode
|
19 |
+
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
20 |
|
21 |
return generated_text
|
22 |
|
23 |
+
title = "ืืืืื: ืคืขื ืื ืืชื ืื ืืืืฆืขืืช ืืื ื ืืืืืืชืืช"
|
24 |
+
description = "ืขื ืืกืืก ืืืื swin ืืฆื ืืชืืื ื, ืืืืื alephbert ืืฆื ืืืงืกื."
|
25 |
+
article = "<p style='text-align: center'>sivan22</p>"
|
26 |
examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]]
|
27 |
|
28 |
#css = """.output_image, .input_image {height: 600px !important}"""
|