Skip to main content

A Python package for creating Gradio applications with Mistral models

Project description

mistral-gradio

is a Python package that makes it very easy for developers to create machine learning apps that are powered by Mistral's API.

Installation

You can install mistral-gradio directly using pip:

pip install mistral-gradio

That's it!

Basic Usage

Just like if you were to use the mistralai API, you should first save your Mistral API key to this environment variable:

export MISTRAL_API_KEY=<your token>

Then in a Python file, write:

import gradio as gr
import mistral_gradio

gr.load(
    name='mistral-large-latest',
    src=mistral_gradio.registry,
).launch()

Run the Python file, and you should see a Gradio Interface connected to the model on Mistral!

ChatInterface

Customization

Once you can create a Gradio UI from an Mistral endpoint, you can customize it by setting your own input and output components, or any other arguments to gr.Interface. For example, the screenshot below was generated with:

import gradio as gr
import mistral_gradio

gr.load(
    name='mistral-large-latest',
    src=mistral_gradio.registry,
    title='Mistral-Gradio Integration',
    description="Chat with Mistral's large model.",
    examples=["Explain quantum gravity to a 5-year old.", "How many R are there in the word Strawberry?"]
).launch()

ChatInterface with customizations

Composition

Or use your loaded Interface within larger Gradio Web UIs, e.g.

import gradio as gr
import mistral_gradio

with gr.Blocks() as demo:
    with gr.Tab("mistral-large"):
        gr.load('mistral-large-latest', src=mistral_gradio.registry)
    with gr.Tab("mistral-medium"):
        gr.load('mistral-medium-latest', src=mistral_gradio.registry)

demo.launch()

Under the Hood

The mistral-gradio Python library has two dependencies: mistralai and gradio. It defines a "registry" function mistral_gradio.registry, which takes in a model name and returns a Gradio app.

Supported Models in Mistral

All chat API models supported by Mistral are compatible with this integration. For a comprehensive list of available models and their specifications, please refer to the Mistral Models documentation.


Note: if you are getting a 401 authentication error, then the Mistral API Client is not able to get the API token from the environment variable. This happened to me as well, in which case save it in your Python session, like this:

import os

os.environ["MISTRAL_API_KEY"] = ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mistral_gradio-0.0.1.tar.gz (159.8 kB view details)

Uploaded Source

Built Distribution

mistral_gradio-0.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file mistral_gradio-0.0.1.tar.gz.

File metadata

  • Download URL: mistral_gradio-0.0.1.tar.gz
  • Upload date:
  • Size: 159.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for mistral_gradio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 937424493161bd155f06a8ebf661954a36843c046f94bdb0e2c4d0267b85cc21
MD5 aa6078a6bd91cc50150d2121eb49b300
BLAKE2b-256 88ba7d49b55209e8195dff1229e5ba8d188300e1bb365be19dde0052a3743a25

See more details on using hashes here.

File details

Details for the file mistral_gradio-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mistral_gradio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1bfa4d13e7538997fccd8264e5e3a8b9d90a8cc26cd8b3207faa083c8758f049
MD5 25fd2eade42d4c0a4a94acba8312e4db
BLAKE2b-256 af78a6acab74bc83e15588e989934f89df7a5fa188267f5488a5fcf6f90f7c35

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page