Update app.py
Browse files1 unmodified line234567891011121314151617181920211 unmodified linefrom PIL import Imageimport pytesseractdef ocr_image(image: Image.Image):# Perform OCR using pytesseractif image is None:return "No image uploaded."text = pytesseract.image_to_string(image, lang='tha+eng') # Thai + English OCRreturn textwith gr.Blocks() as demo:gr.Markdown("## 🖼️ OCR จากภาพ - อัปโหลดและครอบบริเวณที่ต้องการ")with gr.Row():image_input = gr.Image(type="pil", label="อัปโหลดแล้วครอบบริเวณที่ต้องการ OCR", interactive=True)text_output = gr.Textbox(label="ข้อความที่ตรวจพบจาก OCR")image_input.change(fn=ocr_image, inputs=image_input, outputs=text_output)demo.launch()1 unmodified line23456789101112131415161718192021221 unmodified linefrom PIL import Imageimport pytesseractdef ocr_on_cropped(cropped_image: Image.Image):if cropped_image is None:return "กรุณาอัปโหลดและครอบรูปภาพก่อน"# ทำ OCR บนภาพที่ถูกครอบtext = pytesseract.image_to_string(cropped_image, lang="tha+eng")return textwith gr.Blocks() as demo:gr.Markdown("## 📷 OCR จากภาพ - อัปโหลดและครอบเฉพาะบริเวณที่ต้องการ")with gr.Row():image_input = gr.Image(type="pil", interactive=True, label="🖼️ อัปโหลดแล้วครอบบริเวณที่ต้องการ")ocr_result = gr.Textbox(label="📄 ข้อความที่ตรวจพบ")image_input.change(fn=ocr_on_cropped, inputs=image_input, outputs=ocr_result)demo.launch()
app.py+10-9