mimoha commited on
Commit
9d8aa3f
·
verified ·
1 Parent(s): 96d7d6c

Create image.py

Browse files
Files changed (1) hide show
  1. image.py +16 -0
image.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import base64
3
+ from mistralai import Mistral, ImageURLChunk
4
+
5
+ client = Mistral(api_key="YOUR_API_KEY")
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),
12
+ model="mistral-ocr-latest"
13
+ )
14
+ return response.to_dict()
15
+
16
+ gr.Interface(fn=process_image, inputs=gr.Image(type="file"), outputs="json").launch()