The Mistral OCR App is a Streamlit-based web application that leverages the Mistral OCR API to extract text from both PDF documents and images. Users can either provide a URL or upload a local file. The app displays the original document (or image) in a preview alongside the extracted OCR results and offers a seamless download option—all without refreshing the page.
🔗 Live Demo: Mistral OCR App
Experience the power of Mistral OCR in action! Upload PDFs or images and extract text seamlessly with this interactive Streamlit-based OCR app.
- Dual File Support: Process both PDFs and images.
- Multiple Input Methods: Choose between URL input or local file uploads.
- Real-Time Preview: Display the original file (via an iframe for PDFs or using
st.image
for images). - OCR Extraction: Get OCR results presented in a clean, two-column layout.
- Downloadable Results: Download the OCR output with a custom HTML link that avoids a full page refresh.
- Interactive Interface: Built with Streamlit for a smooth and interactive user experience.
- Python 3.7 or later
- Streamlit
- Mistralai Python Client
-
Clone the Repository:
git clone https://github.com/AIAnytime/Mistral-OCR-App.git cd Mistral-OCR-App
-
Create and Activate a Virtual Environment (Optional but Recommended):
On macOS/Linux:
python -m venv venv source venv/bin/activate
On Windows:
python -m venv venv venv\Scripts\activate
-
Install Required Dependencies:
Create a
requirements.txt
file (if not already present) with:streamlit mistralai
Then install them:
pip install -r requirements.txt
-
Set Up Your Mistral API Key:
The app requires a Mistral API key. Export your API key as an environment variable:
-
On macOS/Linux:
export MISTRAL_API_KEY=your_api_key_here
-
On Windows (Command Prompt):
set MISTRAL_API_KEY=your_api_key_here
-
To run the app, use the following command:
streamlit run app.py
-
API Key Entry:
When you launch the app, you'll be prompted to enter your Mistral API key. -
File Type & Source Selection:
Choose whether you want to process a PDF or an Image and select the source type—either via a URL or by uploading a file. -
Processing:
Click the Process button to send the document to the Mistral OCR API. The app then:- Displays a preview of the document in the left column.
- Shows the extracted OCR results in the right column.
- Provides a download link for the OCR output.
-
Download:
Click the download link to save the OCR result as a text file without refreshing the page.
-
app.py:
The main Streamlit application file that contains the logic for:- User input handling (API key, file type, source type)
- Document preparation (base64 encoding for local uploads)
- Calling the Mistral OCR API
- Displaying the preview and OCR results
- Providing a custom download link
-
README.md:
This file, which provides detailed instructions and documentation for the project. -
requirements.txt:
A list of the required Python packages.
Contributions are welcome! If you have suggestions or find issues, please feel free to:
- Open an issue in the repository.
- Submit a pull request with improvements or bug fixes.
This project is licensed under the MIT License.
- Streamlit for making interactive web app development easy.
- Mistralai for their powerful OCR API and Python client.
For any questions or support, please open an issue in this repository or contact [sonu@aianytime.net].