Ferrxni commited on
Commit
c858ae5
·
1 Parent(s): 6aa2ba4

update app

Browse files
Files changed (1) hide show
  1. app.py +40 -36
app.py CHANGED
@@ -1,36 +1,40 @@
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
-
10
- # # Initialize Mistral client with the API key
11
- # client = MistralClient(api_key=api_key)
12
-
13
- # def answer_question(question):
14
- # """Directly ask Mistral the question and return the answer."""
15
- # # Format the user's question for Mistral
16
- # user_message = question
17
-
18
- # # Use the run_mistral function to get an answer
19
- # answer = run_mistral(user_message)
20
-
21
- # return answer
22
-
23
- # def run_mistral(user_message, model="mistral-medium"):
24
- # """Interact with Mistral using chat."""
25
- # messages = [ChatMessage(role="user", content=user_message)]
26
- # chat_response = client.chat(model=model, messages=messages)
27
- # return chat_response.choices[0].message.content
28
-
29
- # app = gr.Interface(fn=answer_question,
30
- # inputs=gr.inputs.Textbox(lines=2, placeholder="Ask a question..."),
31
- # outputs="text",
32
- # title="Your Assistant",
33
- # description="Ask any question, and I'll try to provide an informative answer.")
34
-
35
- # if __name__ == "__main__":
36
- # app.launch(share=True) # Set `share=True` to create a public link
 
 
 
 
 
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