Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,16 @@
|
|
1 |
-
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
2 |
import requests
|
3 |
from PIL import Image
|
4 |
import streamlit as st
|
|
|
5 |
|
|
|
6 |
st.title("Duh!")
|
7 |
-
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
|
8 |
-
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
|
9 |
|
10 |
# load image from the IAM dataset
|
11 |
url = "https://parivahan.gov.in/rcdlstatus/DispplayCaptcha?txtp_cd=1&bkgp_cd=2&noise_cd=2&gimp_cd=3&txtp_length=5&pfdrid_c=true?1429026471&pfdrid_c=true"
|
12 |
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
13 |
|
14 |
-
pixel_values = processor(image, return_tensors="pt").pixel_values
|
15 |
-
generated_ids = model.generate(pixel_values)
|
16 |
-
|
17 |
-
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
18 |
-
|
19 |
col1, col2 = st.columns(2)
|
20 |
-
|
21 |
col1.image(image, use_column_width=True)
|
22 |
-
col2.subheader(f"Detected Text: {
|
|
|
|
|
1 |
import requests
|
2 |
from PIL import Image
|
3 |
import streamlit as st
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
+
pipe = pipeline("image-to-text", model="microsoft/trocr-large-printed")
|
7 |
st.title("Duh!")
|
|
|
|
|
8 |
|
9 |
# load image from the IAM dataset
|
10 |
url = "https://parivahan.gov.in/rcdlstatus/DispplayCaptcha?txtp_cd=1&bkgp_cd=2&noise_cd=2&gimp_cd=3&txtp_length=5&pfdrid_c=true?1429026471&pfdrid_c=true"
|
11 |
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
col1, col2 = st.columns(2)
|
14 |
+
predictions = pipeline(image)
|
15 |
col1.image(image, use_column_width=True)
|
16 |
+
col2.subheader(f"Detected Text: {predictions}")
|