mimoha commited on
Commit
bf3a2bf
·
verified ·
1 Parent(s): 1629bdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -4,8 +4,9 @@ from mistralai import Mistral, ImageURLChunk
4
 
5
  client = Mistral(api_key="RJIqm5OvwoMvLeWrFdv5JBx26tLsSSK7")
6
 
7
- def process_image(image):
8
- encoded = base64.b64encode(image.read()).decode()
 
9
  data_url = f"data:image/jpeg;base64,{encoded}"
10
  response = client.ocr.process(
11
  document=ImageURLChunk(image_url=data_url),
@@ -13,4 +14,8 @@ def process_image(image):
13
  )
14
  return response.to_dict()
15
 
16
- gr.Interface(fn=process_image, inputs=gr.Image(type="file"), outputs="json").launch()
 
 
 
 
 
4
 
5
  client = Mistral(api_key="RJIqm5OvwoMvLeWrFdv5JBx26tLsSSK7")
6
 
7
+ def process_image(image_path):
8
+ with open(image_path, "rb") as image:
9
+ encoded = base64.b64encode(image.read()).decode()
10
  data_url = f"data:image/jpeg;base64,{encoded}"
11
  response = client.ocr.process(
12
  document=ImageURLChunk(image_url=data_url),
 
14
  )
15
  return response.to_dict()
16
 
17
+ gr.Interface(
18
+ fn=process_image,
19
+ inputs=gr.Image(type="filepath"),
20
+ outputs="json"
21
+ ).launch()