Siri23 commited on
Commit
8219e88
·
verified ·
1 Parent(s): 757bdee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load the model
5
+ pipe = pipeline("image-to-text", model="jinhybr/OCR-Donut-CORD")
6
+
7
+ # Function to process the image and extract text
8
+ def extract_text(image):
9
+ # Pass the image to the pipeline
10
+ result = pipe(image)
11
+ # Return the text from the image
12
+ return result[0]['generated_text'] if result else "No text detected"
13
+
14
+ # Define the Gradio interface
15
+ iface = gr.Interface(
16
+ fn=extract_text, # The function that processes the image
17
+ inputs=gr.Image(type="pil"), # Input is an image (PIL format)
18
+ outputs="text", # Output is text
19
+ title="OCR with Donut-CORD Model", # Title of the interface
20
+ description="Upload an image to extract text using the OCR Donut-CORD model.",
21
+ )
22
+
23
+ # Launch the app
24
+ if __name__ == "__main__":
25
+ iface.launch()