Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,9 @@ from mistralai import Mistral, ImageURLChunk
|
|
| 4 |
|
| 5 |
client = Mistral(api_key="RJIqm5OvwoMvLeWrFdv5JBx26tLsSSK7")
|
| 6 |
|
| 7 |
-
def process_image(
|
| 8 |
-
|
|
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|