Spaces:
Paused
Paused
Update components/llm_ocr_api.py
Browse files- components/llm_ocr_api.py +11 -17
components/llm_ocr_api.py
CHANGED
|
@@ -1,21 +1,15 @@
|
|
| 1 |
-
import
|
| 2 |
-
import io
|
| 3 |
-
|
| 4 |
-
def extract_text_from_space(image):
|
| 5 |
-
api_url = "https://huggingface.co/spaces/Hammedalmodel/handwritten_to_text/api/predict"
|
| 6 |
-
|
| 7 |
-
image_bytes = io.BytesIO()
|
| 8 |
-
image.save(image_bytes, format="PNG")
|
| 9 |
-
image_bytes.seek(0)
|
| 10 |
-
|
| 11 |
-
files = {
|
| 12 |
-
"data": ("image.png", image_bytes, "image/png")
|
| 13 |
-
}
|
| 14 |
|
|
|
|
| 15 |
try:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
return f"❌ Error: {str(e)}"
|
|
|
|
| 1 |
+
from gradio_client import Client, handle_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def extract_text_from_space(image_path):
|
| 4 |
try:
|
| 5 |
+
# Create client for Hugging Face Space
|
| 6 |
+
client = Client("Hammedalmodel/handwritten_to_text")
|
| 7 |
+
|
| 8 |
+
# Send image file path to the Space
|
| 9 |
+
result = client.predict(
|
| 10 |
+
image=handle_file(image_path), # handle_file needs a path
|
| 11 |
+
api_name="/predict"
|
| 12 |
+
)
|
| 13 |
+
return result # Expected to be a single string output
|
| 14 |
except Exception as e:
|
| 15 |
return f"❌ Error: {str(e)}"
|