szili2011 commited on
Commit
1e9fcfe
·
verified ·
1 Parent(s): 19bf107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -1,22 +1,23 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the text extraction model
5
- ocr_model = pipeline("image-to-text", model="microsoft/monologg-ocr")
6
 
7
- def extract_text(image):
8
- # Perform OCR
9
- text = ocr_model(image)[0]['generated_text']
10
- return text
11
 
12
- # Create the Gradio interface
13
- iface = gr.Interface(
14
- fn=extract_text,
15
- inputs=gr.Image(type="pil"), # Accepts image input
16
- outputs="text", # Outputs extracted text
17
- title="Image to Text Extractor",
18
- description="Upload an image to extract text from it."
19
  )
20
 
21
- # Launch the interface
22
- iface.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the OCR model
5
+ ocr_model = pipeline("image-to-text", model="microsoft/trocr-large-printed")
6
 
7
+ def recognize_text(image):
8
+ # Use the model on the input image
9
+ result = ocr_model(image)
10
+ return result[0]['generated_text'] # Return the recognized text
11
 
12
+ # Set up the Gradio interface
13
+ interface = gr.Interface(
14
+ fn=recognize_text,
15
+ inputs=gr.Image(type="filepath"), # Use filepath to accept image input
16
+ outputs="text", # Output the recognized text
17
+ title="OCR with Trocr",
18
+ description="Upload an image to recognize text using the Trocr model."
19
  )
20
 
21
+ # Launch the app
22
+ if __name__ == "__main__":
23
+ interface.launch()