Spaces:
Paused
Paused
update app
Browse files
app.py
CHANGED
@@ -1,36 +1,40 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from mistralai.client import MistralClient, ChatMessage
|
3 |
+
import os
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
# Load environment variables
|
7 |
+
load_dotenv()
|
8 |
+
api_key = os.getenv('API_KEY')
|
9 |
+
client = MistralClient(api_key=api_key)
|
10 |
+
model = 'mistral-small'
|
11 |
+
|
12 |
+
|
13 |
+
title = "Gaia Mistral Chat Demo"
|
14 |
+
description = "Example of simple chatbot with Gradio and Mistral AI via its API"
|
15 |
+
placeholder = "Posez moi une question sur l'agriculture"
|
16 |
+
examples = ["Comment fait on pour produire du maïs ?", "Rédige moi une lettre pour faire un stage dans une exploitation agricole", "Comment reprendre une exploitation agricole ?"]
|
17 |
+
|
18 |
+
|
19 |
+
def chat_with_mistral(user_input):
|
20 |
+
messages = [ChatMessage(role="user", content=user_input)]
|
21 |
+
|
22 |
+
chat_response = client.chat(model=model, messages=messages)
|
23 |
+
return chat_response.choices[0].message.content
|
24 |
+
|
25 |
+
app = gr.ChatInterface(
|
26 |
+
fn=chat_with_mistral,
|
27 |
+
chatbot=gr.Chatbot(height=300),
|
28 |
+
textbox=gr.Textbox(placeholder=placeholder, container=False, scale=7),
|
29 |
+
title=title,
|
30 |
+
description=description,
|
31 |
+
theme="soft",
|
32 |
+
examples=examples,
|
33 |
+
cache_examples=True,
|
34 |
+
retry_btn=None,
|
35 |
+
undo_btn="Annuler",
|
36 |
+
clear_btn="Effacer",
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
app.launch(share=True) # Set `share=True` to create a public link
|