raviix46 commited on
Commit
afdb52b
·
verified ·
1 Parent(s): 047eda4

Update components/llm_ocr_api.py

Browse files
Files changed (1) hide show
  1. components/llm_ocr_api.py +11 -17
components/llm_ocr_api.py CHANGED
@@ -1,21 +1,15 @@
1
- import requests
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
- response = requests.post(api_url, files=files)
17
- response.raise_for_status()
18
- result = response.json()
19
- return result["data"][0] if "data" in result else "❌ Unexpected response format."
 
 
 
 
 
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)}"