Spaces:
Running
Running
Update app.py
Browse files
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(
|
34 |
-
# Open the image
|
35 |
-
image = Image.open(
|
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 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
with gr.Column():
|
103 |
-
ocr_output = gr.Textbox(
|
104 |
-
label="Extracted Text",
|
105 |
-
lines=10,
|
106 |
-
interactive=False,
|
107 |
-
)
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
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()
|