harsh-manvar commited on
Commit
52d1916
·
verified ·
1 Parent(s): 3d53d43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -30,9 +30,9 @@ def generate_response(prompt, max_tokens, temperature, top_p):
30
  generated_text = output[0].outputs[0].text
31
  return generated_text
32
 
33
- def ocr_image(image):
34
- # Open the image and preprocess for OCR
35
- image = Image.open(image)
36
  pixel_values = ocr_processor(images=image, return_tensors="pt").pixel_values
37
 
38
  # Perform OCR
@@ -90,27 +90,27 @@ with gr.Blocks() as demo:
90
  )
91
 
92
  with gr.Tab("OCR"):
93
- with gr.Row():
94
- with gr.Column():
95
- image_input = gr.Image(
96
- label="Upload Image",
97
- type="file",
98
- image_mode="RGB",
99
- )
100
- ocr_submit_button = gr.Button("Extract Text")
101
-
102
- with gr.Column():
103
- ocr_output = gr.Textbox(
104
- label="Extracted Text",
105
- lines=10,
106
- interactive=False,
107
- )
108
 
109
- ocr_submit_button.click(
110
- ocr_image,
111
- inputs=[image_input],
112
- outputs=ocr_output,
113
- )
 
 
 
 
 
 
 
114
 
115
  # Launch the app
116
  demo.launch()
 
30
  generated_text = output[0].outputs[0].text
31
  return generated_text
32
 
33
+ def ocr_image(image_path):
34
+ # Open the image from the file path
35
+ image = Image.open(image_path)
36
  pixel_values = ocr_processor(images=image, return_tensors="pt").pixel_values
37
 
38
  # Perform OCR
 
90
  )
91
 
92
  with gr.Tab("OCR"):
93
+ with gr.Row():
94
+ with gr.Column():
95
+ image_input = gr.Image(
96
+ label="Upload Image",
97
+ type="filepath",
98
+ image_mode="RGB",
99
+ )
100
+ ocr_submit_button = gr.Button("Extract Text")
 
 
 
 
 
 
 
101
 
102
+ with gr.Column():
103
+ ocr_output = gr.Textbox(
104
+ label="Extracted Text",
105
+ lines=10,
106
+ interactive=False,
107
+ )
108
+
109
+ ocr_submit_button.click(
110
+ ocr_image,
111
+ inputs=[image_input],
112
+ outputs=ocr_output,
113
+ )
114
 
115
  # Launch the app
116
  demo.launch()