import streamlit as st from PIL import Image from easyocr import Reader import os # הגדרת כותרת האפליקציה st.title("OCR בעברית עם EasyOCR") # יצירת אובייקט ה-Reader של EasyOCR עם עברית (he) # gpu=False כי ב-Hugging Face Spaces בחינם אין GPU reader = Reader(['he'], gpu=False) st.write("העלה תמונה עם כתב יד בעברית, וננסה לזהות את הטקסט") uploaded_file = st.file_uploader("בחר/גרור תמונה", type=["jpg","jpeg","png"]) if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, caption="התמונה שהועלתה", use_container_width=True) if st.button("פענח טקסט"): with st.spinner("מבצע OCR..."): # EasyOCR יכול לקבל גם path, אבל נשתמש בפרמטר detail=0 לקבלת טקסט נטו # נקרא את התמונה ישירות מהבייטים: result = reader.readtext(uploaded_file, detail=0) st.subheader("טקסט מזוהה:") if result: st.write(" ".join(result)) else: st.write("לא זוהה טקסט, ייתכן שהתמונה לא ברורה או שהכתב מורכב מדי.")