Spaces:
Running
Running
import gradio as gr | |
from mistralai.client import MistralClient | |
from mistralai.models.chat_completion import ChatMessage | |
import os | |
title = "Gaia Mistral Chat Demo" | |
description= "Exemple d'assistant avec Gradio et Mistral AI via son API" | |
placeholder= "Posez moi une question sur l'agriculture" | |
examples= ["Comment fait on pour produire du maïs ?"] | |
api_key = os.environ.get("MISTRAL_API_KEY") | |
client = MistralClient(api_key=api_key) | |
model = 'mistral-small' | |
def chat_with_mistral(user_input): | |
messages = [ChatMessage(role="user", content=user_input)] | |
chat_response = client.chat(model=model, messages=messages) | |
return chat_response.choices[0].message.content | |
iface = gr.ChatInterface( | |
fn=chat_with_mistral, | |
chatbot=gr.Chatbot(height=300), | |
textbox=gr.Textbox(placeholder=placeholder, container=False, scale=7), | |
title=title, | |
description=description, | |
theme="soft", | |
examples=examples, | |
cache_examples=True, | |
retry_btn=None, | |
undo_btn="Annuler", | |
clear_btn="Effacer", | |
) | |
iface.launch() |