Spaces:
Sleeping
Sleeping
Create image.py
Browse files
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()
|