Spaces:
Running
Running
fix
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from io import BytesIO
|
|
4 |
import gradio as gr
|
5 |
from mistralai import Mistral
|
6 |
from PIL import Image
|
7 |
-
from pathlib import Path
|
8 |
|
9 |
# Config
|
10 |
VALID_DOCUMENT_EXTENSIONS = {".pdf"}
|
@@ -31,9 +30,9 @@ def do_ocr(input_type, url, file, api_key):
|
|
31 |
api_key = api_key.strip() if api_key and api_key.strip() else os.environ.get("MISTRAL")
|
32 |
if not api_key:
|
33 |
return "Please provide a valid Mistral API key", "", []
|
34 |
-
|
35 |
document_source = None
|
36 |
-
|
37 |
if input_type == "URL":
|
38 |
if not url or url.strip() == "":
|
39 |
return "Please provide a valid URL.", "", []
|
@@ -96,9 +95,10 @@ def do_ocr(input_type, url, file, api_key):
|
|
96 |
|
97 |
return extracted_text.strip(), rendered_markdown.strip(), images
|
98 |
|
|
|
99 |
custom_css = """
|
100 |
body {font-family: 'Helvetica Neue', Helvetica;}
|
101 |
-
.gr-button {background-color: #4CAF50; color: white; border: none; padding: 10px
|
102 |
.gr-button:hover {background-color: #45a049;}
|
103 |
.gr-textbox {margin-bottom: 15px;}
|
104 |
.example-button {background-color: #1E90FF; color: white; border: none; padding: 8px 15px; border-radius: 5px; margin: 5px;}
|
@@ -114,13 +114,14 @@ with gr.Blocks(
|
|
114 |
) as demo:
|
115 |
gr.Markdown("<h1 style='text-align: center;'>Mistral OCR Demo</h1>")
|
116 |
gr.Markdown("<p style='text-align: center;'>Extract text and images from PDFs or images using Mistral's latest OCR model. You can also see markdown live.</p>")
|
117 |
-
gr.Markdown("<p style='text-align: center;'>Provide your Mistral API key below or
|
118 |
|
119 |
with gr.Row():
|
120 |
with gr.Column(scale=1):
|
121 |
api_key_input = gr.Textbox(
|
122 |
label="Mistral API Key",
|
123 |
placeholder="Paste your Mistral API key here",
|
|
|
124 |
type="password",
|
125 |
lines=1
|
126 |
)
|
@@ -132,7 +133,7 @@ with gr.Blocks(
|
|
132 |
)
|
133 |
url_input = gr.Textbox(
|
134 |
label="Document or Image URL",
|
135 |
-
placeholder="e
|
136 |
visible=True,
|
137 |
lines=1
|
138 |
)
|
|
|
4 |
import gradio as gr
|
5 |
from mistralai import Mistral
|
6 |
from PIL import Image
|
|
|
7 |
|
8 |
# Config
|
9 |
VALID_DOCUMENT_EXTENSIONS = {".pdf"}
|
|
|
30 |
api_key = api_key.strip() if api_key and api_key.strip() else os.environ.get("MISTRAL")
|
31 |
if not api_key:
|
32 |
return "Please provide a valid Mistral API key", "", []
|
33 |
+
|
34 |
document_source = None
|
35 |
+
|
36 |
if input_type == "URL":
|
37 |
if not url or url.strip() == "":
|
38 |
return "Please provide a valid URL.", "", []
|
|
|
95 |
|
96 |
return extracted_text.strip(), rendered_markdown.strip(), images
|
97 |
|
98 |
+
|
99 |
custom_css = """
|
100 |
body {font-family: 'Helvetica Neue', Helvetica;}
|
101 |
+
.gr-button {background-color: #4CAF50; color: white; border: none; padding: 10px 15px; border-radius: 5px;}
|
102 |
.gr-button:hover {background-color: #45a049;}
|
103 |
.gr-textbox {margin-bottom: 15px;}
|
104 |
.example-button {background-color: #1E90FF; color: white; border: none; padding: 8px 15px; border-radius: 5px; margin: 5px;}
|
|
|
114 |
) as demo:
|
115 |
gr.Markdown("<h1 style='text-align: center;'>Mistral OCR Demo</h1>")
|
116 |
gr.Markdown("<p style='text-align: center;'>Extract text and images from PDFs or images using Mistral's latest OCR model. You can also see markdown live.</p>")
|
117 |
+
gr.Markdown("<p style='text-align: center;'>Provide your Mistral API key below or set the `MISTRAL` environment variable. Visit <a href='https://console.mistral.ai/'>Mistral AI Console</a> to manage your API key.</p>")
|
118 |
|
119 |
with gr.Row():
|
120 |
with gr.Column(scale=1):
|
121 |
api_key_input = gr.Textbox(
|
122 |
label="Mistral API Key",
|
123 |
placeholder="Paste your Mistral API key here",
|
124 |
+
value=os.environ.get("MISTRAL", ""),
|
125 |
type="password",
|
126 |
lines=1
|
127 |
)
|
|
|
133 |
)
|
134 |
url_input = gr.Textbox(
|
135 |
label="Document or Image URL",
|
136 |
+
placeholder="e.g., https://arxiv.org/pdf/2501.12948",
|
137 |
visible=True,
|
138 |
lines=1
|
139 |
)
|