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.2.tar.gz (159.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mistral_gradio-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f015f040274e9c1e1908f78270d4464060bd03973d78de7917892981a556b69d
MD5 e11d4d2edc5412ac4b8b84db84354762
BLAKE2b-256 ec02d6b670ece4a314b864bd882fc59eb77f8a06eb880708dfe2173b75fc2b69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mistral_gradio-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19f9c93a7cb10bdd848c886502e4e0dd57fdb2bd4eb3e9630394b8331b6d5d7b
MD5 358bebcfda70046b2b8972cdbe6447e0
BLAKE2b-256 f682ad8117622c57d3fd526e190af1f1bb1d0a889bd9a9be55fd5ffc1d6d21bc

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