Spaces:
Running
Running
limits
Browse files
app.py
CHANGED
@@ -3,10 +3,14 @@ import os
|
|
3 |
import base64
|
4 |
import requests
|
5 |
from mistralai import Mistral
|
|
|
6 |
|
7 |
api_key = os.environ["MISTRAL_API_KEY"]
|
|
|
|
|
8 |
client = Mistral(api_key=api_key)
|
9 |
|
|
|
10 |
def encode_image(image_path):
|
11 |
"""Encode the image to base64."""
|
12 |
try:
|
@@ -132,10 +136,12 @@ with gr.Blocks() as demo:
|
|
132 |
fn=perform_ocr_file,
|
133 |
inputs=[file_input, ocr_method_file],
|
134 |
outputs=[file_output, file_raw_output]
|
|
|
|
|
135 |
)
|
136 |
|
137 |
with gr.Tab("Enter URL"):
|
138 |
-
url_input = gr.Textbox(label="Enter
|
139 |
ocr_method_url = gr.Dropdown(choices=["Mistral OCR"], label="Select OCR Method", value="Mistral OCR")
|
140 |
url_output = gr.Markdown(label="Rendered Markdown")
|
141 |
url_raw_output = gr.Textbox(label="Raw Markdown")
|
@@ -153,6 +159,9 @@ with gr.Blocks() as demo:
|
|
153 |
fn=perform_ocr_url,
|
154 |
inputs=[url_input, ocr_method_url],
|
155 |
outputs=[url_output, url_raw_output]
|
|
|
|
|
156 |
)
|
157 |
|
158 |
-
demo.
|
|
|
|
3 |
import base64
|
4 |
import requests
|
5 |
from mistralai import Mistral
|
6 |
+
import time
|
7 |
|
8 |
api_key = os.environ["MISTRAL_API_KEY"]
|
9 |
+
rps_limit = float(os.environ["RPS_LIMIT"])
|
10 |
+
max_queue = int(os.environ["MAX_QUEUE"])
|
11 |
client = Mistral(api_key=api_key)
|
12 |
|
13 |
+
|
14 |
def encode_image(image_path):
|
15 |
"""Encode the image to base64."""
|
16 |
try:
|
|
|
136 |
fn=perform_ocr_file,
|
137 |
inputs=[file_input, ocr_method_file],
|
138 |
outputs=[file_output, file_raw_output]
|
139 |
+
).then(
|
140 |
+
lambda: time.sleep(1/rps_limit)
|
141 |
)
|
142 |
|
143 |
with gr.Tab("Enter URL"):
|
144 |
+
url_input = gr.Textbox(label="Enter a URL to a PDF or Image")
|
145 |
ocr_method_url = gr.Dropdown(choices=["Mistral OCR"], label="Select OCR Method", value="Mistral OCR")
|
146 |
url_output = gr.Markdown(label="Rendered Markdown")
|
147 |
url_raw_output = gr.Textbox(label="Raw Markdown")
|
|
|
159 |
fn=perform_ocr_url,
|
160 |
inputs=[url_input, ocr_method_url],
|
161 |
outputs=[url_output, url_raw_output]
|
162 |
+
).then(
|
163 |
+
lambda: time.sleep(1/rps_limit)
|
164 |
)
|
165 |
|
166 |
+
demo.queue(max_size=max_queue)
|
167 |
+
demo.launch(max_threads=1)
|