NowLoadY commited on
Commit
e941d9b
·
1 Parent(s): fb336e2

Upload 2 files

Browse files
Files changed (2) hide show
  1. ocr_gpt_app.py +24 -0
  2. requirements.txt +3 -0
ocr_gpt_app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import easyocr
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ # Initialize OCR reader and GPT pipeline
6
+ reader = easyocr.Reader(['ch_sim', 'en'])
7
+ gpt = pipeline('text-generation', model='gpt2')
8
+
9
+ # Define the OCR function
10
+ def ocr_gpt(image):
11
+ ocr_result = reader.readtext(image)
12
+ corrected_text = gpt(ocr_result[0][1])[0]['generated_text']
13
+ gpt_opinion = gpt("What do you think about the information in the image?")[0]['generated_text']
14
+ return corrected_text, gpt_opinion
15
+
16
+ # Define Gradio UI components
17
+ image_input = gr.inputs.Image()
18
+ gpt_input = gr.inputs.Textbox(lines=1, label="GPT API Input")
19
+ ocr_output = gr.outputs.Textbox(label="OCR Result (GPT Corrected)")
20
+ gpt_opinion_output = gr.outputs.Textbox(label="GPT Opinion on Image Information")
21
+
22
+ # Create Gradio interface
23
+ iface = gr.Interface(fn=ocr_gpt, inputs=[gpt_input, image_input], outputs=[ocr_output, gpt_opinion_output])
24
+ #iface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ easyocr
2
+ gradio
3
+ transformers