Spaces:
Sleeping
Sleeping
ionosphere
commited on
Commit
·
7af6bd2
1
Parent(s):
a7b8ffc
Add initial config
Browse files- app.py +35 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from mistralai.client import MistralClient
|
3 |
+
from mistralai.models.chat_completion import ChatMessage
|
4 |
+
import os
|
5 |
+
|
6 |
+
title = "Gaia Mistral Chat Demo"
|
7 |
+
description= "Exemple d'assistant avec Gradio et Mistral AI via son API"
|
8 |
+
placeholder= "Posez moi une question sur l'agriculture"
|
9 |
+
examples= ["Comment fait on pour produire du maïs ?"]
|
10 |
+
api_key = os.environ.get("MISTRAL_API_KEY")
|
11 |
+
|
12 |
+
client = MistralClient(api_key=api_key)
|
13 |
+
model = 'mistral-small'
|
14 |
+
|
15 |
+
def chat_with_mistral(user_input):
|
16 |
+
messages = [ChatMessage(role="user", content=user_input)]
|
17 |
+
|
18 |
+
chat_response = client.chat(model=model, messages=messages)
|
19 |
+
return chat_response.choices[0].message.content
|
20 |
+
|
21 |
+
iface = gr.ChatInterface(
|
22 |
+
fn=chat_with_mistral,
|
23 |
+
chatbot=gr.Chatbot(height=300),
|
24 |
+
textbox=gr.Textbox(placeholder=placeholder, container=False, scale=7),
|
25 |
+
title=title,
|
26 |
+
description=description,
|
27 |
+
theme="soft",
|
28 |
+
examples=examples,
|
29 |
+
cache_examples=True,
|
30 |
+
retry_btn=None,
|
31 |
+
undo_btn="Annuler",
|
32 |
+
clear_btn="Effacer",
|
33 |
+
)
|
34 |
+
|
35 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
mistralai==0.0.8
|